Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 05 Feb 1998 00:23:20 +0100 (CET)
From:      Jaroslav Klaus <J.Klaus@sh.cvut.cz>
To:        freebsd-questions@FreeBSD.ORG
Subject:   IPX RAW socket
Message-ID:  <XFMail.980205002320.J.Klaus@sh.cvut.cz>

next in thread | raw e-mail | index | archive | help
This message is in MIME format
--_=XFMail.1.2.p0.FreeBSD:980205002316:9663=_
Content-Type: text/plain; charset=iso-8859-2
Content-Transfer-Encoding: quoted-printable

Hello,

I'd like to send IPX type20 packet. I've writen a small prg but sendto
returns errno=3D56. Is IPX RAW socket implemented in FBSD2.2? Can anybody h=
elp
me with it? I attached my program in this mail. I started it by this way:

%./ipx 0x337130.0x00:00:b4:72:aa:83.0x5500 0.0:00:12:34:56:78.0x5520
couldn't send packet
0.12345678H.5520H : 337130H.b472aa83.5500H -> 0.12345678H.5520H
56: unknown error

And another Q. In ports is there any tool for sending data to network iface=
?
I need resend some ethernet packet captured by 'tcpdump -w <file>'.

Thank you,
--
Jarda



--_=XFMail.1.2.p0.FreeBSD:980205002316:9663=_
Content-Disposition: attachment; filename="ipx.c"
Content-Transfer-Encoding: 7bit
Content-Description: ipx.c
Content-Type: text/plain; charset=us-ascii; name=ipx.c; SizeOnDisk=3841

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/errno.h>

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

#define IPX_DATA_LEN		20

#define IPXPROTO_NETBIOS	20

u_short checksum(u_short * data,u_short length)                                 
{                                                                               
        register long value;                                                    
        u_short i;                                                              
                                                                                
        for(i=0;i<(length>>1);i++)                                              
                value+=data[i];                                                 
                                                                                
        if((length&1)==1)                                                       
                value+=(data[i]<<8);                                            
                                                                                
        value=(value&65535)+(value>>16);                                        
                                                                                
        return(~value);                                                         
}                                                                               


int main(int argc, char ** argv)
{
	struct sockaddr_ipx 	sipx;
	int 			sock,err;
	char 			buffer[sizeof(struct ipx)+IPX_DATA_LEN];
	struct ipx		* ipxheader=(struct ipx *)buffer;
	struct ipx_addr		addr;
	char			src_addr[30];
	char			dst_addr[30];	
	char			sck_addr[30];
		
	if (argc<3)
	{
		fprintf(stderr,"usage: %s src_ipx_addr dst_ipx_addr\n",argv[0]);
		return (-1);
	}
	
	
	bzero(&sipx,sizeof(struct sockaddr_ipx));
	sipx.sipx_family=AF_IPX;
	
        bzero(&buffer, sizeof(struct ipx)+IPX_DATA_LEN);
        
        ipxheader->ipx_len=sizeof(struct ipx)+IPX_DATA_LEN;
        ipxheader->ipx_tc =0;
        ipxheader->ipx_pt =IPXPROTO_NETBIOS;
        
	addr=ipx_addr(argv[2]);
	bcopy(&addr, &sipx.sipx_addr, sizeof(struct ipx_addr));
	bcopy(&addr,&ipxheader->ipx_dna, sizeof(struct ipx_addr));
        addr=ipx_addr(argv[1]);
	bcopy(&addr,&ipxheader->ipx_sna, sizeof(struct ipx_addr));

        ipxheader->ipx_sum=0;//checksum((u_short *)ipxheader, sizeof(struct ipx)
);                                		

	if ((sock=socket(PF_IPX,SOCK_RAW,IPXPROTO_RAW))==-1)
	{
                fprintf(stderr,"couldn't allocate raw socket\n");               
                return (-1);                                                    
 
        }

	sprintf(sck_addr,"%s",ipx_ntoa(sipx.sipx_addr));
	sprintf(src_addr,"%s",ipx_ntoa(ipxheader->ipx_sna));
	sprintf(dst_addr,"%s",ipx_ntoa(ipxheader->ipx_dna));
        
	if((err=sendto(sock, buffer, sizeof(struct ipx)+IPX_DATA_LEN, 0, (struct sockad
dr *) &sipx, sizeof(struct sockaddr_ipx)))==-1)
	{
		fprintf(stderr,"couldn't send packet\n");
		fprintf(stderr,"%s : %s -> %s\n",sck_addr,src_addr,dst_addr);

		switch(errno)
		    {
		    case EBADF:		{ fprintf(stderr,"EBADF\n"); break; }
		    case EACCES:	{ fprintf(stderr,"EACCES\n"); break;}
		    case ENOTSOCK:	{ fprintf(stderr,"ENOTSOCK\n");break;}
		    case EFAULT: 	{ fprintf(stderr,"EFAULT\n"); break;}
		    case EMSGSIZE:	{ fprintf(stderr,"EMSGSIZE\n"); break;}
		    case EAGAIN: 	{ fprintf(stderr,"EAGAIN\n"); break;}
		    case ENOBUFS:	{ fprintf(stderr,"ENOBUFS\n"); break;}
		    case EHOSTUNREACH:	{ fprintf(stderr,"EHOSTUNREACH\n"); break;}
		    default:		{ fprintf(stderr,"%d: unknown error\n",errno); break;}
		    }
		return (-1);
	}
	
	fprintf(stderr,"IPX packet was sent:\n%s : %s -> %s\n",sck_addr,src_addr,dst_ad
dr);
	return (0);
}

--_=XFMail.1.2.p0.FreeBSD:980205002316:9663=_--
End of MIME message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?XFMail.980205002320.J.Klaus>