• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Why can't my socket receive any packets?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Why can't my socket receive any packets?


  • Subject: Why can't my socket receive any packets?
  • From: zheng cheng <email@hidden>
  • Date: Wed, 11 Apr 2007 10:06:57 +0800 (CST)

I'm a newbie to OS X, i have search my problem in google, i find someone has the same problem with me, he has posted a mail to this maillist,i just forward his/her mail,

Thanks for your help!

Re: Newbie question about receiving raw ethernet packet

Hello Jean,

the BSD sample doesn't really show how to capture Phase 1 Ethernet packets. I tried a quick modification and found the same problem which you describe. I recall that at one times, things worked. Maybe an alternative would be to implement a BPF socket. I'll send a sample to you directly.

rich kubota

At 5:04 PM -0700 4/13/05, Jean Bovet wrote:
Hi,

I'm really new to network programming and I've been reading e-mails from this list as well as the BSDLLCTest example provided by Apple. I'm trying to extract from this example the lines needed to capture raw ethernet packet (I have written a C++ tool that I launch using sudo). Everything works well - no error reported - but I don't receive anything (I'm using another computer to send raw packet to my main machine).

Here is my code:

******

int create_socket(void)
{
fd = socket(AF_NDRV, SOCK_RAW, 0);
if(fd < 0) {
printf("socket() error = %d (%s)\n", errno, get_error(errno));
return errno;
}
return NO_ERR;
}

void create_socket_address(char *name)
{
saddr.sa_len = sizeof(struct sockaddr);
saddr.sa_family = AF_NDRV;
strcpy(saddr.sa_data, name);
}

int bind_socket(void)
{
int err = bind(fd, &saddr, sizeof(saddr));
if(err != 0) {
printf("bind error = %d (%s)\n", err, get_error(err));
return err;
}
return NO_ERR;
}

void set_listening_protocol(void)
{
struct ndrv_protocol_desc desc;
struct ndrv_demux_desc demux_desc[1];

bzero(&desc, sizeof(desc)); // zero out the strucuture
bzero(&demux_desc, sizeof(demux_desc)); // zero out the strucuture


    desc.version = NDRV_PROTOCOL_DESC_VERS;
desc.protocol_family = NDRV_DEMUXTYPE_ETHERTYPE;
desc.demux_count = (u_int32_t)1;
desc.demux_list = (struct ndrv_demux_desc*)&demux_desc;

	demux_desc[0].type = NDRV_DEMUXTYPE_ETHERTYPE;
demux_desc[0].length = sizeof(unsigned short);
demux_desc[0].data.ether_type = htons(0x888e);

int result = setsockopt(fd, SOL_NDRVPROTO, NDRV_SETDMXSPEC, (caddr_t)&desc, sizeof(desc));
if (result != 0)
printf("setsockopt error = %d\n", result);
}


int main (int argc, const char * argv[])
{
// Create the socket (needs super-user privileges - use 'sudo')
int err = create_socket();
if(err != 0)
return err;

	// Ethernet 0 (built-in)
create_socket_address("en1");

	// Bind socket
err = bind_socket();
if(err != 0)
return err;

	set_listening_protocol();

	char buffer[2048];
int addr_len = sizeof(saddr);
int n = recvfrom(fd, buffer, 2048, 0, &saddr, &addr_len);
// int n = recvfrom(fd, buffer, 2048, 0, NULL, NULL);
printf("%d bytes read\n", n);

    return 0;
}

****

I probably put incorrect values in my set_listening_protocol()... any tips ? Also, what happens if I set the two last parameters from the recvfrom() to NULL ?

Thanks for any help!

Jean Bovet

This email sent to email@hidden

--
Sincerely,
Rich Kubota
email@hidden
(408) 974-6212


Best Wishes,
CZ



抢注雅虎免费邮箱-3.5G容量,20M附件!
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Why can't my socket receive any packets?
      • From: Rich Kubota <email@hidden>
  • Prev by Date: Re: Delay in NSHTTPCookieStorage
  • Next by Date: Re: Why can't my socket receive any packets?
  • Previous by thread: Re: How to get dialup modem info, and how to set a connection
  • Next by thread: Re: Why can't my socket receive any packets?
  • Index(es):
    • Date
    • Thread