Part 1: Experimental purposes
Master the three steps of the sockaddr_in application and be proficient in using the relevant functions in the process.
PART2: Experimental content
1 1#include <stdio.h>2 2#include <stdlib.h>3 3#include <string.h>4 4#include <unistd.h>5 5#include <sys/types.h>6 6#include <sys/socket.h>7 7#include <netinet/inch.h>8 8#include <arpa/inet.h>9 9 #definePORT 1234Ten TenMain () One One { A A inti; - - structsockaddr_in server; - -Bzero (&server,sizeof(server)); the theprintf"Your server ' s IP init mem is \ n"); - - for(i=0;i<sizeof(server); i++) - - { - -printf"%02x", * ((unsignedChar*) (&server) +i)); + + } - -printf"\ n"); + +printf"\ n"); A Aserver.sin_family=af_inet; at atserver.sin_port=htons (PORT); - -SERVER.SIN_ADDR.S_ADDR=INET_ADDR ("192.168.0.21"); - -printf"Your server ' s IP sin_family is%d\n", server.sin_family); - -printf"Your server ' s IP is%s, port is%d\n", Inet_ntoa (SERVER.SIN_ADDR), Ntohs (Server.sin_port)); - -printf"Your server ' s length is%d\n",sizeof(server)); - -printf"Your server ' s IP mem is \ n"); in in for(i=0;i<sizeof(server); i++) - - { to toprintf"%02x", * ((unsignedChar*) (&server) +i)); + + } - -printf"\ n"); the the return; * *}
Network programming Experiment Two