:i	static char d_bind_sccs_id[] = "%W% %G%";
:1#include "V.h"
#include "sys_socket.h"
/*
* This wrapper for the bind system call also notes the address/port returned,
* and caches it in the openfile entry.
*/
d_bind(s,name,namelen)
	int s;
	SKAD *name;
	int namelen;
{	int e=0,v=0;
	SKin *sp;
:6	V6 "bind(%d,%08X,%d)",s,name,namelen D;
	if (!name || (namelen <= 0)) {
:2		V2 "bind(%d,%08X,%d) invalid arg.",s,name,namelen D;
		e = EINVAL;
		Fail;
	}
:5	V5 "Bind %d to address \"%s\"",s,SymSockAddr(name) D;
:7	H7(name,namelen,"SKin");
	errno = 0;
	v = bind(s,name,namelen);
	e = errno;
:6	V6 "bind(%d,%08X,%d)=%d [Err %d=%s=%s]",s,name,namelen,v,Errinfo D;
	if (v == 0) {
		File *fp;
		sp = (SKin*)name;
		if ((IPfmly(sp) == AF_INET) && (fp = d_openfile(s))) {
			fp->addr = sp->sin_addr.s_addr;
			fp->port = ntohs(sp->sin_port);
		}
:5		V5 "Bound %d to address \"%s\"",s,SymSockAddr(name) D;
	}
fail:
	errno = e;
	return v;
}

/*
* Produce a symbolic dump of a sockaddr_in structure.
*/
dmpSKin(p)
	SKin *p;
{
	V1 "SKin fmly=%d addr=%08X=%s port=%04X=%d %s."
		,p->sin_family
		,p->sin_addr
		,ipdot(&p->sin_addr)
		,p->sin_port
		,ntohs(p->sin_port)
		,SymSockAddr(p)
	 D;
}

