[examples] added helper external functions to make code more clean;
parent
cf5399738f
commit
ff106b93f0
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Secure X Message Passing Library v2 examples.
|
||||
*
|
||||
* (c) Originally written by somebody else ...
|
||||
* (c) Alexander Vdolainen 2013-2015 <avdolainen@gmail.com>
|
||||
*
|
||||
* libsxmp is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* libsxmp is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.";
|
||||
*
|
||||
* This is a simple helpers to make code more clean;
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <dirent.h>
|
||||
#define __USE_GNU
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <sys/types.h>
|
||||
#include <limits.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/resource.h>
|
||||
#include <netdb.h>
|
||||
#include <unistd.h>
|
||||
#include <netinet/in.h>
|
||||
#include <stdint.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
int openlistener_socket(int port)
|
||||
{
|
||||
int sd;
|
||||
struct sockaddr_in addr;
|
||||
|
||||
sd = socket(PF_INET, SOCK_STREAM, 0);
|
||||
memset(&addr, 0, sizeof(addr));
|
||||
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons(port);
|
||||
addr.sin_addr.s_addr = INADDR_ANY;
|
||||
|
||||
if(bind(sd, (struct sockaddr*)&addr, sizeof(addr)) != 0) {
|
||||
perror("can't bind port");
|
||||
abort();
|
||||
}
|
||||
if(listen(sd, 10) != 0) {
|
||||
perror("Can't configure listening port");
|
||||
abort();
|
||||
}
|
||||
|
||||
return sd;
|
||||
}
|
||||
|
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Secure X Message Passing Library v2 examples.
|
||||
*
|
||||
* (c) Originally written by somebody else ...
|
||||
* (c) Alexander Vdolainen 2013-2015 <avdolainen@gmail.com>
|
||||
*
|
||||
* libsxmp is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* libsxmp is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.";
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __SXMP_EXAMPLES_HELPERS_H__
|
||||
#define __SXMP_EXAMPLES_HELPERS_H__
|
||||
|
||||
int openlistener_socket(int port);
|
||||
|
||||
#endif /* __SXMP_EXAMPLES_HELPERS_H__ */
|
Loading…
Reference in New Issue