mirror of
https://sourceware.org/git/glibc.git
synced 2025-12-24 17:51:17 +03:00
initial import
This commit is contained in:
23
manual/examples/isockad.c
Normal file
23
manual/examples/isockad.c
Normal file
@@ -0,0 +1,23 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netdb.h>
|
||||
|
||||
void
|
||||
init_sockaddr (struct sockaddr_in *name,
|
||||
const char *hostname,
|
||||
unsigned short int port)
|
||||
{
|
||||
struct hostent *hostinfo;
|
||||
|
||||
name->sin_family = AF_INET;
|
||||
name->sin_port = htons (port);
|
||||
hostinfo = gethostbyname (hostname);
|
||||
if (hostinfo == NULL)
|
||||
{
|
||||
fprintf (stderr, "Unknown host %s.\n", hostname);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
name->sin_addr = *(struct in_addr *) hostinfo->h_addr;
|
||||
}
|
||||
Reference in New Issue
Block a user