当前位置: 技术问答>linux和unix
诚心急求LINUX下网络编程的C源码!
来源: 互联网 发布时间:2015-07-27
本文导语: 要求实现得到本机的网络情况:本机的IP地址(可能是多个),与之对应的网络是否连通/断开,网络的数据流量.最好是直接拿来就可以用的. 不胜感激!!! | 看看这些有帮助吗。 /*****************************...
要求实现得到本机的网络情况:本机的IP地址(可能是多个),与之对应的网络是否连通/断开,网络的数据流量.最好是直接拿来就可以用的.
不胜感激!!!
不胜感激!!!
|
看看这些有帮助吗。
/*****************************************************************************
Simple TCP (stream; HTTP) server
Chris Giese http://www.execpc.com/~geezer
Release date: ?
This code is public domain (no copyright).
You can do whatever you want with it.
Build with MinGW:
gcc -c -O0 -Wall -W tcp-srv.c
gcc -otcp-srv.exe tcp-srv.o -lwsock32
Build with Borland C++ 5.5:
bcc32 -c -O2 -w tcp-srv.c
bcc32 tcp-srv.obj -otcp-srv.exe
Revised Jan 25, 2004
- changed select() timeout so client has 3 seconds to send HTTP request
- proper checking of return values from socket API functions
- using WSAGetLastError() instead of errno for Winsock
*****************************************************************************/
#include /* atexit() */
#include /* memset() */
#include /* printf() */
#if defined(__WIN32__)
#include
#include /* kbhit(), getch() */
#define SOCKERR WSAGetLastError()
#elif defined(linux)
#include
#include
#include
#include
#include
#include
#define closesocket(S) close(S)
#define SOCKERR errno
static int kbhit(void);
static int getch(void);
#elif defined(__TURBOC__)
#include
#include "socket.h"
#define SOCKERR errno
#elif defined(__WATCOMC__)
#if defined(__386__)
#error This is a 16-bit program
#endif
#include
#include "socket.h"
#else
#error Unsupported OS or compiler
#endif
#define PORT 80 /* HTTP */
#define BACKLOG 5
#define BUF_SIZE 256
/*****************************************************************************
*****************************************************************************/
int main(void)
{
static const char greet[] =
"n"
"H E L L On"
"Hello!n";
/* put big buffer in data segment, so 16-bit DOS program doesn't crash */
static char buf[BUF_SIZE];
/**/
int l_sock, c_sock, i, count, sin_size;
struct sockaddr_in my_adr, their_adr;
struct timeval timeout;
fd_set read_handles;
#if defined(__WIN32__)
WSADATA wsdata;
/* Winsock start up */
WSAStartup(0x0101, &wsdata);
atexit((void (*)(void))WSACleanup);
#endif
/* create listener socket */
printf("calling socket()...n");
l_sock = socket(AF_INET, SOCK_STREAM, 0);
if(l_sock
/*****************************************************************************
Simple TCP (stream; HTTP) server
Chris Giese http://www.execpc.com/~geezer
Release date: ?
This code is public domain (no copyright).
You can do whatever you want with it.
Build with MinGW:
gcc -c -O0 -Wall -W tcp-srv.c
gcc -otcp-srv.exe tcp-srv.o -lwsock32
Build with Borland C++ 5.5:
bcc32 -c -O2 -w tcp-srv.c
bcc32 tcp-srv.obj -otcp-srv.exe
Revised Jan 25, 2004
- changed select() timeout so client has 3 seconds to send HTTP request
- proper checking of return values from socket API functions
- using WSAGetLastError() instead of errno for Winsock
*****************************************************************************/
#include /* atexit() */
#include /* memset() */
#include /* printf() */
#if defined(__WIN32__)
#include
#include /* kbhit(), getch() */
#define SOCKERR WSAGetLastError()
#elif defined(linux)
#include
#include
#include
#include
#include
#include
#define closesocket(S) close(S)
#define SOCKERR errno
static int kbhit(void);
static int getch(void);
#elif defined(__TURBOC__)
#include
#include "socket.h"
#define SOCKERR errno
#elif defined(__WATCOMC__)
#if defined(__386__)
#error This is a 16-bit program
#endif
#include
#include "socket.h"
#else
#error Unsupported OS or compiler
#endif
#define PORT 80 /* HTTP */
#define BACKLOG 5
#define BUF_SIZE 256
/*****************************************************************************
*****************************************************************************/
int main(void)
{
static const char greet[] =
"n"
"H E L L On"
"Hello!n";
/* put big buffer in data segment, so 16-bit DOS program doesn't crash */
static char buf[BUF_SIZE];
/**/
int l_sock, c_sock, i, count, sin_size;
struct sockaddr_in my_adr, their_adr;
struct timeval timeout;
fd_set read_handles;
#if defined(__WIN32__)
WSADATA wsdata;
/* Winsock start up */
WSAStartup(0x0101, &wsdata);
atexit((void (*)(void))WSACleanup);
#endif
/* create listener socket */
printf("calling socket()...n");
l_sock = socket(AF_INET, SOCK_STREAM, 0);
if(l_sock
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
站内导航:
特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!