#include <stdio.h>
#include <sys/socket.h>
#include <unistd.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <stdlib.h>
#include <time.h>
#include<iostream>
#include<string.h>
using namespace std;
struct usbinfo{
string vendor;
string produce;
string guest;
string host;
};
#if 0
#include "usbip.h"
#include "usbip_common.h"
#include "utils.h"
#endif
#define SERVER_PORT 44444 // define the defualt connect port id
#define LENGTH_OF_LISTEN_QUEUE 10 // length of listen queue in server
#define BUFFER_SIZE 255
#define WELCOME_MESSAGE "welcome to connect the server. "
int main(int argc, char** argv)
{ struct usbinfo usbinfo1;
int servfd,clifd;
char *server=NULL;
char str[255];
int ret = -1;
struct sockaddr_in servaddr,cliaddr;
if ((servfd = socket(AF_INET,SOCK_STREAM, 0 )) < 0 )
{
printf( " create socket error!\n " );
exit( 1 );
}
bzero( & servaddr, sizeof (servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(SERVER_PORT);
servaddr.sin_addr.s_addr = htons(INADDR_ANY);
if (bind(servfd,( struct sockaddr * ) & servaddr, sizeof (servaddr)) < 0 )
{
printf( " bind to port %d failure!\n " ,SERVER_PORT);
exit( 1 );
}
if (listen(servfd,LENGTH_OF_LISTEN_QUEUE) < 0 )
{
printf( " call listen failure!\n " );
exit( 1 );
}
while ( 1 )
{ // server loop will nerver exit unless any body kill the process
char buf[BUFFER_SIZE];
long timestamp;
socklen_t length = sizeof (cliaddr);
clifd = accept(servfd,( struct sockaddr * ) & cliaddr, & length);
if (clifd < 0 )
{
printf( " error comes when call accept!\n " );
break ;
}
// strcpy(buf,WELCOME_MESSAGE);
// inet_ntop(INET_ADDRSTRLEN,cliaddr.sin_addr,buf,BUFFER_SIZE);
printf( " from client,IP:%s,Port:%d\n " ,inet_ntoa(cliaddr.sin_addr),ntohs(cliaddr.sin_port));
server=inet_ntoa(cliaddr.sin_addr);
printf("server is :%s\n",server);
// timestamp = time(NULL);
//strcat(buf, " timestamp in server: " );
// strcat(buf,ctime( & timestamp));
length = recv(clifd, &usbinfo1, sizefo(usbinfo), 0);
if (length < 0)
{
printf( " error comes when recieve data from server " );
exit( 1 );
}
//printf( " end from client : %s\n", buf);
// snprintf(str,255,"usbip attach --host %s --busid %s",server,buf);
//printf("system's str is :%s\n",str);
// system(str);
close(clifd);
} // exit
close(servfd);
//sleep(5);
return 0 ;
}
没有合适的资源?快使用搜索试试~ 我知道了~
自动共享usb设备
共26个文件
cpp:7个
o:5个
cpp~:3个
需积分: 9 10 下载量 114 浏览量
2013-05-08
15:27:22
上传
评论
收藏 1.35MB ZIP 举报
温馨提示
基于usb/ip项目可以自动共享usb设备
资源推荐
资源详情
资源评论
收起资源包目录
myusb.zip (26个子文件)
myusb
usbbind_list.o 3KB
usbbind_unbind.o 3KB
server.c 3KB
usbbind.h~ 510B
server 12KB
usbbind.cpp 5KB
usbbind_bak.o 2KB
usbbind.h 512B
usbbind_unbind.cpp 1KB
使用方法截图
usbbind_bind.png 531KB
usbbind_list.png 538KB
unbind.png 176KB
usbbind_bind.cpp~ 6KB
usbbind.o 2KB
usbbind_list.cpp 1KB
usbbind_unbind.cpp~ 1KB
usbbind_bak.cpp~ 5KB
Makefile~ 320B
usbbind.h.gch 868KB
usbbind_bind.cpp 6KB
server.cpp 5KB
Makefile 413B
usbbind 18KB
usbbind_bind.o 7KB
usbbind_bak.cpp 5KB
server2
server.cpp 5KB
共 26 条
- 1
资源评论
zhaoyuyang2
- 粉丝: 0
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功