DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download
Index: T u

⟦2f18d3e35⟧ TextFile

    Length: 1783 (0x6f7)
    Types: TextFile
    Names: »udp.c«

Derivation

└─⟦9ae75bfbd⟧ Bits:30007242 EUUGD3: Starter Kit
    └─⟦697af93db⟧ »EurOpenD3/network/snmp/mit-snmp.tar.Z« 
        └─⟦57bbcbe75⟧ 
            └─⟦this⟧ »./bsd/udp.c« 

TextFile


/*
 *	$Header: udp.c,v 1.1 89/01/11 22:10:30 jrd Exp $
 *	Author: J. Davin
 *	Copyright 1988, 1989, Massachusetts Institute of Technology
 *	See permission and disclaimer notice in file "notice.h"
 */

#include	<notice.h>

#include	<sys/types.h>
#include	<sys/socket.h>
#include	<netinet/in.h>

#include	<ctypes.h>
#include	<debug.h>
#include	<local.h>
#include	<udp.h>

typedef		struct			UdpTag {

		int			udpSocket;
		struct	sockaddr	udpSockAddr;
		CIntfType		udpRefCnt;

		}			UdpType;

typedef		UdpType		*UdpPtrType;

SmpStatusType	udpSend (udp, bp, n)

SmpSocketType		udp;
CBytePtrType		bp;
CIntfType		n;

{
	UdpPtrType		tp;
	int			result;

	if (udp == (SmpSocketType) 0) {
		return (errBad);
	}

	DEBUG0 ("udpSend:\n");
	DEBUGBYTES (bp, n);
	DEBUG0 ("\n");

	tp = (UdpPtrType) udp;
	do {	
		result = sendto (tp->udpSocket, (char *) bp,
			(int) n, (int) 0,
			& (tp->udpSockAddr), sizeof (struct sockaddr_in));
		n -= result;
		bp += result;

	} while ((result > 0) && (n > 0));

	if (result < 0) {
		perror ("udpSend");
		return (errBad);
	}
	else {
		return (errOk);
	}
}

SmpSocketType	udpNew (so, host, port)

int			so;
u_long			host;
u_short			port;

{
	UdpPtrType		tp;
	struct	sockaddr_in	*sin;

	tp = (UdpPtrType) malloc ((unsigned) sizeof (*tp));
	if (tp != (UdpPtrType) 0) {
		(void) bzero ((char *) tp, (int) sizeof (*tp));
		tp->udpSocket = so;
		tp->udpRefCnt = 1;
		sin = (struct sockaddr_in *) & tp->udpSockAddr;
		sin->sin_family = AF_INET;
		sin->sin_port = port;
		sin->sin_addr.s_addr = host;
	}

	return ((SmpSocketType) tp);
}

SmpSocketType	udpFree (udp)

SmpSocketType	udp;

{
	UdpPtrType		tp;

	if (udp != (SmpSocketType) 0) {
		tp = (UdpPtrType) udp;
		if ((tp->udpRefCnt--) <= 0) {
			(void) free ((char *) tp);
		}
	}
	return ((SmpSocketType) 0);
}