aboutsummaryrefslogtreecommitdiffstats
path: root/sdk/net/udpsocket.c
blob: 2127ac3f3945993a67738d5cdae32d8fe4b65140 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*
 * Create and bind a udp socket for a server.
 * $Id$
 * Copyright (c) 1997 by Tycho Softworks.
 * For conditions of distribution and reuse see product license.
 */

#include <net/socket.h>

SOCKET	udpsocket(char *mask, int port)
{
	SOCKET	so;
	struct	sockaddr_in	saddr;
	struct	in_addr *aptr;
	
	so = socket(AF_INET, SOCK_DGRAM, 0);
	if(so == INVALID_SOCKET)
		return so;

	saddr.sin_family =  AF_INET;
	saddr.sin_port = htons(port);
	aptr = getnetaddr(mask);
	if(!aptr)
	{
		endsocket(so);
		return INVALID_SOCKET;
	}
	saddr.sin_addr = *aptr;		
		
	if(bind(so, (struct sockaddr *)&saddr, sizeof(saddr)))
	{
		endsocket(so);
		return INVALID_SOCKET;
	}
	return so;
}