?
Solved

help me in accessing LAN using C programming

Posted on 2004-03-28
6
Medium Priority
?
340 Views
Last Modified: 2010-04-15
Hi all!
i'm trying to access LAN using C programming.
till now i could access serial port, but i'm not sure how to acess LAN.
could someone help me in this regard!!!!

thanks in advance.

vasu
0
Comment
Question by:vasureddym
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 

Expert Comment

by:PCT
ID: 10701918
If you what to send data through your Ethernet card you can use Sockets.
You will have to include some header probably socket.h for unix or winsock.h for windows into your code.

Don't forget to include the required libraries before compiling.


0
 
LVL 12

Expert Comment

by:stefan73
ID: 10702264
Hi vasureddym,
Depends on what you mean by "access LAN". Low-level access of network card?
Or do you want to access a particular server via SMB?
Do you want to access some TCP/IP service, like FTP?

Cheers,
Stefan
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 10710771
ok heres what you need to do

open a socket:


fd = socket(PF_INET, SOCK_PACKET, htons(ETH_P_ALL));
if (fd < 0) {
sprintf(ebuf, "socket: %s", strerror(errno));
goto failed;
}



/* check device type */

memset(&ifr, 0, sizeof(ifr));
strncpy(ifr.ifr_name, device, sizeof(ifr.ifr_name));
if (ioctl(fd, SIOCGIFHWADDR, &ifr) < 0 ) {
sprintf(ebuf, "SIOCGIFHWADDR: %s", strerror(errno));
goto failed;
}

if (ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER) {
sprintf(ebuf, "unsupported physical layer type 0x%x (ethernet
only)",
ifr.ifr_hwaddr.sa_family);
goto failed;
}


memcpy(ethaddr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);


if you need promisc mode, don't forget to restore device flags.


ifr.ifr_flags |= IFF_PROMISC;
if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0 ) {
sprintf(ebuf, "SIOCSIFFLAGS: %s", strerror(errno));
goto failed;
}
atexit(restore_ifr);


/****/


void restore_ifr(void)
{
int fd;


fd = socket(PF_INET, SOCK_PACKET, htons(0x0003));
if (fd < 0)
fprintf(stderr, "linux socket: %s", strerror(errno));
else if (ioctl(fd, SIOCSIFFLAGS, &saved_ifr) < 0)
fprintf(stderr, "linux SIOCSIFFLAGS: %s", strerror(errno));
}


To receive/send stuff, use recvmsg/sendmsg,
look into the concepts of the structs:
msghdr, ethhdr, iovec, and sockaddr_pkt to build/decode packages.

for more info http:20660168.html
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Author Comment

by:vasureddym
ID: 10721449
Hi all!

Thanks PCT for your Participation.

Hi Stefan73, all I want is to learn accessing/transferring files on LAN using protocols like TCP/IP.
I tried the following simple program. It, is not making use of any protocols.
thanks for your participation.

Hi sunnycoder, i'm beginner to Network programming in C. terms like 'sockets' are new to me,. can you suggest me something..
0
 
LVL 45

Accepted Solution

by:
sunnycoder earned 150 total points
ID: 10721477
www.ecst.csuchico.edu/~beej/guide/net/html/

go though it .. by the time you finish it, you would no longer feel like a beginner ;o)
0
 
LVL 2

Author Comment

by:vasureddym
ID: 10958535
thanks sunny!
i found that link very useful!
i didn't go through it completely. right now i'm  in another project, so i have to keep this topic aside for few days.
however, it is not a good idea to keep this Question for so long time.
i want to close this for the time being.
anyways, thanks
-vasureddym
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question