help writing via NIT interface
Frederick J. Hirsch
fjh at bbn.com
Mon Oct 8 07:30:00 AEST 1990
I am using the NIT interface and I have opened it using code that follows.
With this code in place, I can read the Ethernet packets using the *read*
command. The problem I am having is with writing out to the NIT port.
if((nitfds = open("/dev/nit", O_RDWR)) < 0) {
perror("nit open");
exit(1);
}
if(ioctl(nitfds, I_SRDOPT, (char *) RMSGD) < 0) {
perror("ioctl");
printf("unable to set up discrete messages?\n");
exit(-1);
}
if(ioctl(nitfds, I_PUSH, "pf") < 0) {
perror("ioctl");
printf("Unable to set pf on nit port\n");
exit(-1);
}
/* bind to the ether interface and set the flags */
strncpy(ifr.ifr_name, etherif, sizeof(ifr.ifr_name));
ifr.ifr_name[sizeof(ifr.ifr_name) - 1] = '\0';
si.ic_cmd = NIOCBIND;
si.ic_len = sizeof(ifr);
si.ic_dp = (char *) 𝔦
if(ioctl(nitfds, I_STR, (char *) &si) < 0) {
perror("ioctl");
printf("Unable to bind nit port\n");
exit(-1);
}
flags = NI_PROMISC;
si.ic_cmd = NIOCSFLAGS;
si.ic_len = sizeof(flags);
si.ic_dp = (char *) &flags;
if(ioctl(nitfds, I_STR, (char *) &si) < 0) {
perror("ioctl");
printf("Unable to set flags for nit port\n");
exit(-1);
}
if(ioctl(nitfds, I_FLUSH, (char *)FLUSHRW) < 0) {
perror("ioctl");
printf("Failed to flush\n");
exit(-1);
}
Then I try to use *putmsg* to write out to the nit interface and I do not
get any error messages. But, it is not sending any packet out because
when I monitor the ethernet with etherfind, I don't see anything.
struct ether_addr *target;
struct sockaddr sa;
int offset = sizeof(sa.sa_data);
u_char *buf = data_buf;
struct strbuf ctl, data;
sa.sa_family = AF_UNSPEC;
bzero(sa.sa_data, offset);
bcopy((char *) target, sa.sa_data, sizeof(struct ether_addr));
ctl.maxlen = ctl.len = sizeof(sa);
ctl.buf = (char *)&sa;
data.maxlen = data.len = len;
data.buf = (char *)buf;
if (putmsg(nitfds, &ctl, &data, 0) < 0) {
perror("Error writing ethernet message.\n");
exit(3);
}
My question is how should the control and data fields in *putmsg* be set
up? Do I need to make the control part point to a sockaddr struct which
has the family defined and the destination address defined as target in
the sockaddr data part? I have tried to use *write* instead which didn't
give me any error messages, but didn't work either.
Any help that you could give me would be greatly appreciated. I am
running on a Sun 3/80 with Sun OS 4.0.3.
Thanks,
Karen Pitrone
(508) 671-1323
kpitrone at bbn.com
More information about the Comp.sys.sun
mailing list