, entonces no entendi lo que quisiste decir perdona pero no creo que nadie te ayude
Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.
Mostrar Mensajes MenúCita de: Khronos14 en 6 Junio 2011, 14:31 PM
A parte de lo que dijo Akai, aprende a escribir como dios manda.
"que veneficio hay?" Aquí me sangraron los ojos...
/**********************************************************************
* client.c --- Demonstrate a simple client.
* Tom Kelliher
*
* This program will connect to a simple iterative server and exchange
* messages. The single command line argument is the server's hostname.
* The server is expected to be accepting connection requests from
* SERVER_PORT.
*
* The same message is sent three times over separate connections,
* demonstrating that different ephemeral ports are used for each
* connection.
**********************************************************************/
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#define DATA "The sea is calm tonight, the tide is full . . ."
#define SERVER_PORT 5001
#define BUFFER_SIZE 1024
/* prototypes */
void die(const char *);
void pdie(const char *);
/**********************************************************************
* main
**********************************************************************/
int main(int argc, char *argv[]) {
int sock; /* fd for socket connection */
struct sockaddr_in server; /* Socket info. for server */
struct sockaddr_in client; /* Socket info. about us */
int clientLen; /* Length of client socket struct. */
struct hostent *hp; /* Return value from gethostbyname() */
char buf[BUFFER_SIZE]; /* Received data buffer */
int i; /* loop counter */
if (argc != 2)
die("Usage: client hostname");
/* Open 3 sockets and send same message each time. */
for (i = 0; i < 3; ++i)
{
/* Open a socket --- not bound yet. */
/* Internet TCP type. */
if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0)
pdie("Opening stream socket");
/* Prepare to connect to server. */
bzero((char *) &server, sizeof(server));
server.sin_family = AF_INET;
if ((hp = gethostbyname(argv[1])) == NULL) {
sprintf(buf, "%s: unknown host\n", argv[1]);
die(buf);
}
bcopy(hp->h_addr, &server.sin_addr, hp->h_length);
server.sin_port = htons((u_short) SERVER_PORT);
/* Try to connect */
if (connect(sock, (struct sockaddr *) &server, sizeof(server)) < 0)
pdie("Connecting stream socket");
/* Determine what port client's using. */
clientLen = sizeof(client);
if (getsockname(sock, (struct sockaddr *) &client, &clientLen))
pdie("Getting socket name");
if (clientLen != sizeof(client))
die("getsockname() overwrote name structure");
printf("Client socket has port %hu\n", ntohs(client.sin_port));
/* Write out message. */
if (write(sock, DATA, sizeof(DATA)) < 0)
pdie("Writing on stream socket");
/* Prepare our buffer for a read and then read. */
bzero(buf, sizeof(buf));
if (read(sock, buf, BUFFER_SIZE) < 0)
pdie("Reading stream message");
printf("C: %s\n", buf);
/* Close this connection. */
close(sock);
}
exit(0);
}
/**********************************************************************
* pdie --- Call perror() to figure out what's going on and die.
**********************************************************************/
void pdie(const char *mesg) {
perror(mesg);
exit(1);
}
/**********************************************************************
* die --- Print a message and die.
**********************************************************************/
void die(const char *mesg) {
fputs(mesg, stderr);
fputc('\n', stderr);
exit(1);
}
Man pages (short for manual pages) are the extensive documentation that comes preinstalled with almost all substantial Unix and Unix-like operating systems. The Unix command used to display them is man. Each page is a self-contained document.
NAME
stdio.h - include definitions for standard buffered input/output
SYNOPSIS
#include <stdio.h>
DESCRIPTION
The <stdio.h> header includes the following kinds of definitions:
Constants subsection of stdio.h(4)
Data Types subsection of stdio.h(4)
External Variables subsection of stdio.h(4)
Function Prototypes subsection of stdio.h(4)
Inclusion of the <stdio.h> header may make visible all symbols from the <stddef.h> header.
Constants
The following macro names are defined as positive integral constant expressions.
BUFSIZ
Size of <stdio.h> buffers.
FILENAME_MAX
Maximum size in bytes of the longest file name string that the system guarantees can be opened.
FOPEN_MAX
Number of streams that the system guarantees can be open simultaneously. The value will be at least eight.
_IOFBF
Input and output fully buffered.
_IOLBF
Input and output line buffered.
_IONBF
Input and output unbuffered.
L_ctermid
Maximum size of character array to hold ctermid() output.
L_tmpnam
Maximum size of character array to hold tmpnam() output.
SEEK_CUR
Seek relative to current position.
SEEK_END
Seek relative to end-of-file.
SEEK_SET
Seek relative to start-of-file.
TMP_MAX
Minimum number of unique file names generated by tmpnam(). Maximum number of times an application can call tmpnam() reliably. The value of TMP_MAX will be at least 10,000.
The following defined constant is scheduled to be withdrawn from a future version of the Single UNIX Specification:
L_cuserid
Maximum size of character array to hold cuserid() output.
Macros
The following macro name is defined as a negative integral constant expression:
EOF
End-of-file return value.
The following macro name is defined as a null pointer constant:
NULL
Null pointer.
The following macro name is defined as a string constant:
P_tmpdir
Default directory prefix for tempnam().
The following macro names are defined as expressions of type pointer to FILE:
stderr
Standard error output stream.
stdin
Standard input stream.
stdout
Standard output stream.
Data Types
The following data types are defined through typedef:
FILE
A structure containing information about a file.
fpos_t
Type containing all information needed to specify uniquely every position within a file.
size_t
Unsigned integral type of the result of the sizeof operator.
va_list
Defined for variables used to traverse a variable argument list, as described in the stdarg.h(4) reference page.
External Variables
The following are defined as external variables. These external variables are scheduled to be withdrawn from a future version of the Single UNIX Specification.
extern char *optarg
extern int opterr
extern int optind
extern int optopt
These variables are also defined in the <unistd.h> header.
Function Prototypes
The following are declared as functions and may also be defined as macros. An application programmer can use an #undef statement to remove the macro definition and ensure that the program uses the actual function.
void clearerr(FILE *stream);
char *ctermid(char *s);
int fclose(FILE *stream);
FILE *fdopen(int fildes, const char * mode);
int feof(FILE *stream);
int ferror(FILE *stream);
int fflush(FILE *stream);
int fgetc(FILE *stream);
int fgetpos(FILE *stream, fpos_t *pos);
char *fgets(char *s, int n, FILE *stream);
int fileno(FILE *stream);
FILE *fopen(const char *filename, const char *mode);
int fprintf(FILE *stream, const char *format, ...);
int fputc(int c, FILE *stream);
int fputs(const char *s, FILE *stream);
size_t fread(void *ptr, size_t size, size_t nitems, FILE *stream);
FILE *freopen(const char *filename, const char *mode,
FILE *stream);
int fscanf(FILE *stream, const char *format, ...);
int fseek(FILE *stream, long int offset, int whence);
int fsetpos(FILE *stream, const fpos_t *pos);
long int ftell(FILE *stream);
size_t fwrite(const void *ptr, size_t size, size_t nitems,
FILE *stream);
int getc(FILE *stream);
int getchar(void);
char *gets(char *s);
int getw(FILE *stream);
int pclose(FILE *stream);
void perror(const char *s);
FILE *popen(const char *command, const char *mode);
int printf(const char *format, ...);
int putc(int c, FILE *stream);
int putchar(int c);
int puts(const char *s);
int putw(int w, FILE *stream);
int remove(const char *path);
int rename(const char *old, const char *new);
void rewind(FILE *stream);
int scanf(const char *format, ...);
void setbuf(FILE *stream, char *buf);
int setvbuf(FILE *stream, char *buf, int type, size_t size);
int sprintf(char *s, const char *format, ...);
int sscanf(const char *s, const char *format, int ...);
char *tempnam(const char *dir, const char *pfx);
FILE *tmpfile(void);
char *tmpnam(char *s);
int ungetc(int c, FILE *stream);
int vfprintf(FILE *stream, const char *format, va_list ap);
int vprintf(const char *format, va_list ap);
int vsprintf(char *s, const char *format, va_list ap);
The following declared functions are scheduled to be withdrawn from a future version of the Single UNIX Specification:
char *cuserid(char *s);
int getopt(int argc, const char *argv[], const char *optstring);
SEE ALSO
clearerr(3), ctermid(3), cuserid(3), fclose(3), fdopen(3), feof(3), ferror(3), fflush(3), fgetc(3), fgetpos(3), fgets(3), fileno(3), fopen(3), fputc(3), fputs(3), fread(3), freopen(3), fseek(3), fsetpos(3), ftell(3), fwrite(3), getc(3), getchar(3), getopt(3), gets(3), getw(3), getwchar(3), pclose(3), perror(3), popen(3), printf(3), putc(3), putchar(3), puts(3), putw(3), putwchar(3), remove(3), rename(2), rewind(3), scanf(3), setbuf(3), setvbuf(3), sscanf(3), system(3), tempnam(3), tmpfile(3), tmpnam(3), ungetc(3), vprintf(3), stdarg.h(4), stddef.h(4), systypes.h(4), stdin(5), xshstdiostr(5)