mirror of
https://github.com/riba2534/TCP-IP-NetworkNote.git
synced 2026-03-31 17:20:19 +08:00
完成到第三章3.4 P48
This commit is contained in:
23
ch03/inet_aton.c
Normal file
23
ch03/inet_aton.c
Normal file
@@ -0,0 +1,23 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <arpa/inet.h>
|
||||
void error_handling(char *message);
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char *addr = "127.232.124.79";
|
||||
struct sockaddr_in addr_inet;
|
||||
|
||||
if (!inet_aton(addr, &addr_inet.sin_addr))
|
||||
error_handling("Conversion error");
|
||||
else
|
||||
printf("Network ordered integer addr: %#x \n", addr_inet.sin_addr.s_addr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void error_handling(char *message)
|
||||
{
|
||||
fputs(message, stderr);
|
||||
fputc('\n', stderr);
|
||||
exit(1);
|
||||
}
|
||||
Reference in New Issue
Block a user