473,387 Members | 1,578 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

convert a single to multiuser.. in sock.c program

OZ
the serproxy claim itself a multi-thread proxy thing.

I have sent email to write the original writer and there is no replay after
3 weeks. my configuration and setting are good.

http://www.lspace.nildram.co.uk/freeware.html

I installed it in rh 9.0

I found it is single user only.
do any one know how to change the single program in c program into a multi
/*
* sock.c
*
* socket routines
*
* (C)1999 Stefano Busti
*
*/
#include <stdlib.h>

#include "sock.h"

#if defined(SOCK_BSD)
# include <unistd.h>
# include <sys/types.h>
# include <sys/socket.h>
# include <netdb.h>
# include <netinet/in.h>
# include <arpa/inet.h>
# include <fcntl.h>
# include <sys/ioctl.h>
#elif defined(SOCK_WIN)
# define ioctl ioctlsocket
#endif

int sock_start(void)
{
#if defined(SOCK_BSD)
return 0;
#elif defined (SOCK_WIN)
WORD wVersionRequested;
WSADATA wsaData;
wVersionRequested = MAKEWORD(1, 1);
return WSAStartup(wVersionRequested, &wsaData);
#endif
}
void sock_finish(void)
{
#if defined(SOCK_WIN)
WSACleanup();
#endif
}

int tcp_init(tcpsock_s *sock, int port)
{
int optval = 1;

//struct protoent *ent;
struct sockaddr_in name;

//ent = getprotobyname("TCP");

//if (!ent)
// return -1;

sock->fd = socket(AF_INET, SOCK_STREAM, 0/*ent->p_proto*/);

if (sock->fd < 0)
return -1;

/* Allow reuse of existing TIME_WAIT sockets */
if (setsockopt(sock->fd, SOL_SOCKET, SO_REUSEADDR,
(void *)&optval, sizeof(optval)))
{
tcp_cleanup(sock);
return -1;
}

if (ioctl(sock->fd, FIONBIO, &optval))
{
tcp_cleanup(sock);
return -1;
}

name.sin_family = AF_INET;
name.sin_port = htons(port);
name.sin_addr.s_addr = htonl(INADDR_ANY);

if (bind(sock->fd, (struct sockaddr *)&name, sizeof(name)) < 0)
{
tcp_cleanup(sock);
return -1;
}

sock->port = port;

return 0;
}

void tcp_cleanup(tcpsock_s *sock)
{
#if defined(SOCK_BSD)
close(sock->fd);
#elif defined(SOCK_WIN)
closesocket(sock->fd);
#endif
}

int tcp_listen(tcpsock_s *sock)
{
return listen(sock->fd, 0);
}

tcpsock_s *tcp_accept(tcpsock_s *sock)
{
struct sockaddr addr;
int addrlen;
int fd;
tcpsock_s *newsock;

addrlen = sizeof(addr);

fd = accept(sock->fd, &addr, &addrlen);

if (fd < 0)
return NULL;

newsock = malloc(sizeof(tcpsock_s));

if (newsock)
newsock->fd = fd;

return newsock;
}

void tcp_refuse(tcpsock_s *sock)
{
tcpsock_s *temp = tcp_accept(sock);

if (temp)
{
/* Disconnect immediately */
tcp_disconnect(temp);

/* Clean up */
tcp_cleanup(temp);
free(temp);
}
}

int tcp_connect(tcpsock_s *sock, char *host, int port)
{
struct sockaddr_in name;
struct hostent *hostinfo;
u_long addr;

name.sin_family = AF_INET;
name.sin_port = htons(port);

addr = inet_addr(host);
hostinfo = gethostbyaddr((char *)&addr, 4, PF_INET);
/*hostinfo = gethostbyname(hostname);*/

if (hostinfo == NULL)
return -1;

name.sin_addr = *(struct in_addr *) hostinfo->h_addr;

return connect(sock->fd, (struct sockaddr *)&name, sizeof(name));
}

void tcp_disconnect(tcpsock_s *sock)
{
shutdown(sock->fd, 2);
}

#ifdef SOCK_BSD
__inline
#endif
int tcp_read(tcpsock_s *sock, void *buf, size_t count)
{
#if defined(SOCK_BSD)
return read(sock->fd, buf, count);
#elif defined(SOCK_WIN)
return recv(sock->fd, buf, count, 0);
#endif
}

#ifdef SOCK_BSD
__inline
#endif
int tcp_write(tcpsock_s *sock, void *buf, size_t count)
{
#if defined(SOCK_BSD)
return write(sock->fd, buf, count);
#elif defined(SOCK_WIN)
return send(sock->fd, buf, count, 0);
#endif
}

int tcp_getport(tcpsock_s *sock)
{
return sock->port;
}

void tcp_debug(tcpsock_s *sock, FILE *f)
{
fprintf(f, "tcp_socket {\n");
fprintf(f, "\tfd = %d\n", sock->fd);
fprintf(f, "\tport = %d\n", sock->port);
fprintf(f, "}\n\n");
}

---

mcu development team
http://arm.web7days.com
Nov 14 '05 #1
5 2623
"OZ" <OZ@NOSPAMOZ.com> wrote in message
news:c0*********@imsp212.netvigator.com...
the serproxy claim itself a multi-thread proxy thing.


Your query and the code you posted are not topical for
comp.lang.c

Before posting here again, please read:
http://www.angelfire.com/ms3/bchambl...me_to_clc.html

Thank you.

-Mike
Nov 14 '05 #2
OZ

Mike Wahler <mk******@mkwahler.net> wrote in message
news:6U******************@newsread2.news.pas.earth link.net...
"OZ" <OZ@NOSPAMOZ.com> wrote in message
news:c0*********@imsp212.netvigator.com...
the serproxy claim itself a multi-thread proxy thing.
Your query and the code you posted are not topical for
comp.lang.c

Before posting here again, please read:
http://www.angelfire.com/ms3/bchambl...me_to_clc.html

Thank you.

this is a "C" program program, a single user program has be changed to
mutliple user.



-Mike

Nov 14 '05 #3

"OZ" <OZ@NOSPAMOZ.com> wrote in message
news:c0*********@imsp212.netvigator.com...

Mike Wahler <mk******@mkwahler.net> wrote in message
news:6U******************@newsread2.news.pas.earth link.net...
"OZ" <OZ@NOSPAMOZ.com> wrote in message
news:c0*********@imsp212.netvigator.com...
the serproxy claim itself a multi-thread proxy thing.
Your query and the code you posted are not topical for
comp.lang.c

Before posting here again, please read:
http://www.angelfire.com/ms3/bchambl...me_to_clc.html

Thank you.

this is a "C" program program,


Simply saying that doesn't make it so.

Your program contains *many* nonstandard extensions (for example,
not one of the #included headers is standard), it's not ISO standard
C, which is the topic here. Did you not read the document whose
link I cited above?
a single user program has be changed to
mutliple user.


The C langauge has no notion of 'single user' or 'multi user'.
Those are operating system concepts. Judging from what I saw
in the code, you'll probably get the best help from Unix group.

-Mike
Nov 14 '05 #4
OZ wrote:
the serproxy claim itself a multi-thread proxy thing.
I have sent email to write the original writer
and there is no reply after 3 weeks.
my configuration and setting are good.

http://www.lspace.nildram.co.uk/freeware.html

I installed it in rh 9.0

I found it is single user only.
Does any one know how to change the single program in c program into a multi


No.

This is not the right place to get the answers you want.
Try contacting the author again.
If you can't get the author to help you,
you will probably need to find a different package
that does what you want to do. Good luck.

Nov 14 '05 #5
Mac
On Sat, 07 Feb 2004 23:59:25 +0000, E. Robert Tisdale wrote:
OZ wrote:
the serproxy claim itself a multi-thread proxy thing.
I have sent email to write the original writer
and there is no reply after 3 weeks.
my configuration and setting are good.

http://www.lspace.nildram.co.uk/freeware.html

I installed it in rh 9.0

I found it is single user only.
Does any one know how to change the single program in c program into a multi


No.

This is not the right place to get the answers you want.
Try contacting the author again.
If you can't get the author to help you,
you will probably need to find a different package
that does what you want to do. Good luck.


The OZ could also try another newsgroup, such as comp.unix.programmer, but
should read the FAQ for that group prior to posting there.

Mac

Nov 14 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: MJL | last post by:
This is a mysql/php question (but a little more on the mysql side.) The two are so closely related these days, I thought it would be ok to ask here. I installed on my Suse Linux system mysql 4.0...
1
by: OZ | last post by:
the serproxy claim itself a multi-thread proxy thing. I have sent email to write the original writer and there is no replay after 3 weeks. my configuration and setting are good. ...
1
by: jiing | last post by:
Now let me describe what I have done and my purpose: Originally, I want to user ports to install phpBB But I found that phpBB doesn't support mysql 5.x (but the ports installed mySQL 5.0.0...
2
by: siliconmike | last post by:
I have a single instance of MySQL package installed on FreeBSD. I run 2 servers. The second server is run with this command: shell> mysqld_safe --defaults-extra-file=/root/my2.cnf & some...
29
by: Mark B | last post by:
We have an Access app (quite big) at www.orbisoft.com/download. We have had requests by potential users to have it converted to an SQL version for them since there corporate policy excludes them...
25
by: cory | last post by:
Hi, I have an Access database and am having an ASP.NEt application written for it. It is almost complete. I have a hosting company that I signed up with a month ago but before I did anything I...
2
by: Deano | last post by:
One of the more challenging things on my app's wishlist is to make it multi-user on a LAN. For the record my app was always intended to a single-user but things have changed. It's mostly...
1
by: Bob Miller | last post by:
Hello. I need to convert some small Java source to C#. Can anybody help me? ============================================================================================ private SocketChannel...
2
by: Michal Stankoviansky | last post by:
Hi Environment: some version of Slackware, Apache 2.2.x, PHP 5.1.5, MySQL 5.0.24. The issue: I'm using Zend Framework Zend_Db component (which uses PDO). We have 2 mysql socket related...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.