Beispiel #1
0
int main(int argc, char *argv[])
{
    int port;
    int sock;
    char buf[BUFSIZ];
    size_t msglen;
    struct sockaddr_in saddr;
    socklen_t saddrlen;

    if (argc == 1 || (port = atoi(argv[1])) <= 0)
    {
	fprintf(stderr, "usage: dgrecv portnumber\n");
	exit(1);
    }

    if ((sock = make_dgram_server_socket(port)) == -1)
    {
	oops("cannot make socket", 2);
    }

    saddrlen = sizeof(saddr);
    while ((msglen = recvfrom(sock, buf, BUFSIZ, 0, (struct sockaddr*)&saddr, &saddrlen)) > 0)
    {
	buf[msglen] = '\0';
	printf ("dgrecv: got a message: %s\n", buf);
	say_who_called(&saddr);
    }

    return 0;
}
/****************************************************************************
 *  * setup() - initialize license server
 *   */
setup()
{
	sd = make_dgram_server_socket(SERVER_PORTNUM);
	if ( sd == -1 )
		oops("make socket");
	free_all_tickets();
	return sd;
}