return STG_CLIENT_ST::Get().PostAuth(userName, serviceType);
}
-const STG_PAIR * stgPreAcctImpl(const char * userName, const char * serviceType)
+/*const STG_PAIR * stgPreAcctImpl(const char * userName, const char * serviceType)
{
return STG_CLIENT_ST::Get().PreAcct(userName, serviceType);
-}
+}*/
const STG_PAIR * stgAccountingImpl(const char * userName, const char * serviceType, const char * statusType, const char * sessionId)
{
const STG_PAIR * stgAuthorizeImpl(const char * userName, const char * serviceType);
const STG_PAIR * stgAuthenticateImpl(const char * userName, const char * serviceType);
const STG_PAIR * stgPostAuthImpl(const char * userName, const char * serviceType);
-const STG_PAIR * stgPreAcctImpl(const char * userName, const char * serviceType);
+/*const STG_PAIR * stgPreAcctImpl(const char * userName, const char * serviceType);*/
const STG_PAIR * stgAccountingImpl(const char * userName, const char * serviceType, const char * statusType, const char * sessionId);
void deletePairs(const STG_PAIR * pairs);
*/
static int stg_authorize(void *, REQUEST *request)
{
- VALUE_PAIR * pwd;
- VALUE_PAIR * svc;
const STG_PAIR * pairs;
const STG_PAIR * pair;
size_t count = 0;
DEBUG("rlm_stg: stg_authorize() request password field: '%s'", request->password->vp_strvalue);
}
// Here we need to define Framed-Protocol
- svc = pairfind(request->packet->vps, PW_SERVICE_TYPE);
+ VALUE_PAIR * svc = pairfind(request->packet->vps, PW_SERVICE_TYPE);
if (svc) {
DEBUG("rlm_stg: stg_authorize() Service-Type defined as '%s'", svc->vp_strvalue);
pairs = stgAuthorizeImpl((const char *)request->username->vp_strvalue, (const char *)svc->vp_strvalue);
pair = pairs;
while (!emptyPair(pair)) {
- pwd = pairmake(pair->key, pair->value, T_OP_SET);
+ VALUE_PAIR * pwd = pairmake(pair->key, pair->value, T_OP_SET);
pairadd(&request->config_items, pwd);
DEBUG("Adding pair '%s': '%s'", pair->key, pair->value);
++pair;
*/
static int stg_authenticate(void *, REQUEST *request)
{
- VALUE_PAIR * svc;
- VALUE_PAIR * pwd;
const STG_PAIR * pairs;
const STG_PAIR * pair;
size_t count = 0;
DEBUG("rlm_stg: stg_authenticate()");
- svc = pairfind(request->packet->vps, PW_SERVICE_TYPE);
+ VALUE_PAIR * svc = pairfind(request->packet->vps, PW_SERVICE_TYPE);
if (svc) {
DEBUG("rlm_stg: stg_authenticate() Service-Type defined as '%s'", svc->vp_strvalue);
pairs = stgAuthenticateImpl((const char *)request->username->vp_strvalue, (const char *)svc->vp_strvalue);
pair = pairs;
while (!emptyPair(pair)) {
- pwd = pairmake(pair->key, pair->value, T_OP_SET);
+ VALUE_PAIR * pwd = pairmake(pair->key, pair->value, T_OP_SET);
pairadd(&request->reply->vps, pwd);
++pair;
++count;
*/
static int stg_accounting(void *, REQUEST * request)
{
- VALUE_PAIR * sttype;
- VALUE_PAIR * svc;
- VALUE_PAIR * sessid;
- VALUE_PAIR * pwd;
const STG_PAIR * pairs;
const STG_PAIR * pair;
size_t count = 0;
DEBUG("rlm_stg: stg_accounting()");
- svc = pairfind(request->packet->vps, PW_SERVICE_TYPE);
- sessid = pairfind(request->packet->vps, PW_ACCT_SESSION_ID);
- sttype = pairfind(request->packet->vps, PW_ACCT_STATUS_TYPE);
+ VALUE_PAIR * svc = pairfind(request->packet->vps, PW_SERVICE_TYPE);
+ VALUE_PAIR * sessid = pairfind(request->packet->vps, PW_ACCT_SESSION_ID);
+ VALUE_PAIR * sttype = pairfind(request->packet->vps, PW_ACCT_STATUS_TYPE);
if (!sessid) {
DEBUG("rlm_stg: stg_accounting() Acct-Session-ID undefined");
pairs = stgAccountingImpl((const char *)request->username->vp_strvalue, (const char *)svc->vp_strvalue, (const char *)sttype->vp_strvalue, (const char *)sessid->vp_strvalue);
} else {
DEBUG("rlm_stg: stg_accounting() Service-Type undefined");
- pairs = stgAccountingImpl((const char *)request->username->vp_strvalue, (const char *)svc->vp_strvalue, (const char *)sttype->vp_strvalue, (const char *)sessid->vp_strvalue);
+ pairs = stgAccountingImpl((const char *)request->username->vp_strvalue, "", (const char *)sttype->vp_strvalue, (const char *)sessid->vp_strvalue);
}
} else {
DEBUG("rlm_stg: stg_accounting() Acct-Status-Type := NULL");
pair = pairs;
while (!emptyPair(pair)) {
- pwd = pairmake(pair->key, pair->value, T_OP_SET);
+ VALUE_PAIR * pwd = pairmake(pair->key, pair->value, T_OP_SET);
pairadd(&request->reply->vps, pwd);
++pair;
++count;
static int stg_postauth(void *, REQUEST *request)
{
- VALUE_PAIR * svc;
- VALUE_PAIR * pwd;
const STG_PAIR * pairs;
const STG_PAIR * pair;
size_t count = 0;
DEBUG("rlm_stg: stg_postauth()");
- svc = pairfind(request->packet->vps, PW_SERVICE_TYPE);
+ VALUE_PAIR * svc = pairfind(request->packet->vps, PW_SERVICE_TYPE);
if (svc) {
DEBUG("rlm_stg: stg_postauth() Service-Type defined as '%s'", svc->vp_strvalue);
pair = pairs;
while (!emptyPair(pair)) {
- pwd = pairmake(pair->key, pair->value, T_OP_SET);
+ VALUE_PAIR * pwd = pairmake(pair->key, pair->value, T_OP_SET);
pairadd(&request->reply->vps, pwd);
++pair;
++count;
return true;
}
-bool PROTO::ERR_Proc(const void * buffer, USER * user)
+bool PROTO::ERR_Proc(const void * /*buffer*/, USER * user)
{
-const ERR_8 * packet = static_cast<const ERR_8 *>(buffer);
-const char * ptr = static_cast<const char *>(buffer);
-
//uint32_t len = packet->len;
#ifdef ARCH_BE
hdr.protoVer[1] = 8; // IA_PROTO_VER
unsigned char buffer[2048];
-memset(buffer, 0, sizeof(buffer));
memcpy(buffer, packet, length);
memcpy(buffer, &hdr, sizeof(hdr));
while (users_iter != usersList.end())
{
Authorize(*users_iter);
- users_iter++;
+ ++users_iter;
}
//isRunning = true;
printfd(__FILE__, "User removed from list %s\n", u->GetLogin().c_str());
break;
}
- users_iter++;
+ ++users_iter;
}
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void * AUTH_STRESS::Run(void * d)
{
-AUTH_STRESS * ia;
-ia = (AUTH_STRESS *)d;
+AUTH_STRESS * ia = static_cast<AUTH_STRESS *>(d);
ia->isRunning = true;
printfd(__FILE__, "AUTH_STRESS::Unauthorize - user: '%s'\n", (*users_iter)->GetLogin().c_str());
}
- users_iter++;
+ ++users_iter;
}
sleep(1);
template <typename varParamType>
class CHG_BEFORE_NOTIFIER: public PROPERTY_NOTIFIER_BASE<varParamType> {
public:
+ CHG_BEFORE_NOTIFIER() : auth(NULL) {}
void Notify(const varParamType & oldValue, const varParamType & newValue);
void SetUser(USER_PTR u) { user = u; }
USER_PTR GetUser() {return user; }
template <typename varParamType>
class CHG_AFTER_NOTIFIER: public PROPERTY_NOTIFIER_BASE<varParamType> {
public:
+ CHG_AFTER_NOTIFIER() : auth(NULL) {}
void Notify(const varParamType & oldValue, const varParamType & newValue);
void SetUser(USER_PTR u) { user = u; }
USER_PTR GetUser() {return user; }
class ADD_USER_NONIFIER: public NOTIFIER_BASE<USER_PTR> {
public:
- ADD_USER_NONIFIER() {}
+ ADD_USER_NONIFIER() : auth(NULL) {}
virtual ~ADD_USER_NONIFIER() {}
void SetAuthorizator(AUTH_STRESS * a) { auth = a; }
class DEL_USER_NONIFIER: public NOTIFIER_BASE<USER_PTR> {
public:
- DEL_USER_NONIFIER() {}
+ DEL_USER_NONIFIER() : auth(NULL) {}
virtual ~DEL_USER_NONIFIER() {}
void SetAuthorizator(AUTH_STRESS * a) { auth = a; }
SRCS = ./debug_cap.cpp \
./checksum.c \
- ./icmp.c \
./ip.c \
- ./misc.c \
./packet.c \
- ./socket.c \
- ./tcp.c \
- ./udp.c
+ ./tcp.c
STGLIBS = common
$Author: faust $
*/
-#include <stdio.h>
+#include "debug_cap.h"
+
+#include "libpal.h"
+
+#include "stg/plugin_creator.h"
+#include "stg/traffcounter.h"
+#include "stg/common.h"
+
+#include <cstdio>
+#include <csignal>
+
#include <unistd.h>
-#include <signal.h>
#include <sys/types.h>
-#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
-#include "libpal.h"
-#include "stg/plugin_creator.h"
-#include "stg/traffcounter.h"
-#include "debug_cap.h"
+extern volatile time_t stgTime;
//-----------------------------------------------------------------------------
void WriteStat(uint32_t u, uint32_t d)
PLUGIN_CREATOR<DEBUG_CAP> cdc;
}
-extern "C" BASE_PLUGIN * GetPlugin();
+extern "C" PLUGIN * GetPlugin();
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
-BASE_PLUGIN * GetPlugin()
+PLUGIN * GetPlugin()
{
return cdc.GetPlugin();
}
}
//-----------------------------------------------------------------------------
DEBUG_CAP::DEBUG_CAP()
+ : nonstop(false),
+ isRunning(false),
+ traffCnt(NULL)
{
-isRunning = false;
-nonstop = false;
}
//-----------------------------------------------------------------------------
void DEBUG_CAP::SetTraffcounter(TRAFFCOUNTER * tc)
if (!isRunning)
break;
- stgUsleep(200000);
+ usleep(200000);
//printf(".");
}
{
printfd(__FILE__, "=====================| pid: %d |===================== \n", getpid());
-DEBUG_CAP * dc = (DEBUG_CAP *)data;
+DEBUG_CAP * dc = static_cast<DEBUG_CAP *>(data);
dc->isRunning = true;
RAW_PACKET rp;
t = stgTime;
tm = localtime(&t);
int min = tm->tm_min;
-int sec = tm->tm_sec;
char cliIP[20];
char srvIP[20];
-char trashIP1[20];
-char trashIP2[20];
while (dc->nonstop)
{
for (int i = 8; i <= 252; i++)
{
-
usize = random()%100 + 100;
- dsize = random()%500 + 900;
-
+ dsize = random()%500 + 900;
+
for (int j = 2; j < 11; j++)
{
- sprintf(cliIP, "192.168.%d.%d", j, i);
+ sprintf(cliIP, "192.168.%d.%d", j, i);
sprintf(srvIP, "10.1.%d.%d", random()%8, 1);
rp = MakeTCPPacket(srvIP, cliIP, 80, random()%2 + 2000, dsize);
{
printfd(__FILE__, "=====================| pid: %d |===================== \n", getpid());
-DEBUG_CAP * dc = (DEBUG_CAP *)data;
+DEBUG_CAP * dc = static_cast<DEBUG_CAP *>(data);
dc->isRunning = true;
RAW_PACKET rp;
{
printfd(__FILE__, "=====================| pid: %d |===================== \n", getpid());
-DEBUG_CAP * dc = (DEBUG_CAP *)data;
+DEBUG_CAP * dc = static_cast<DEBUG_CAP *>(data);
dc->isRunning = true;
RAW_PACKET rp;
int a = 0;
sleep(3);
-struct tm * tm;
time_t t;
uint32_t u = 0;
uint32_t d = 0;
int dsize = 1500;
t = stgTime;
-tm = localtime(&t);
char cliIP[20];
char srvIP1[20];
printfd(__FILE__, "pkt_free error!\n");
}
rp.dataLen = -1;
-strcpy(rp.iface, "eth0");
return rp;
}
//-----------------------------------------------------------------------------
+++ /dev/null
-/* $Id: icmp.c,v 1.1 2005/12/12 18:14:22 nobunaga Exp $
-
-Copyright (C) 2002 Marc Kirchner <kirchner@stud.fh-heilbronn.de>
-
-This library 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 2.1 of the License, or (at your option) any later version.
-
-This library 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 Lesser General Public
-License along with this library; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-*/
-
-#include "libpal.h"
-
-int
-pkt_icmp_header(struct packet *pkt, unsigned char type, unsigned char code, unsigned short int checksum)
-{
-
- struct icmp *icmp;
- if (pkt) {
- icmp = (struct icmp *) pkt->pkt_ptr;
- icmp->icmp_type = type;
- icmp->icmp_code = code;
- icmp->icmp_cksum = htons(checksum);
- return 0;
- } else
- return EPKTINVALPTR;
-}
-
-int pkt_icmp_addr_mask(struct packet *pkt, unsigned short int id, unsigned short int seqno, unsigned int mask, char *cmask)
-{
- struct icmp *icmp;
- struct in_addr inetaddr;
-
- if (pkt) {
- icmp = (struct icmp *)pkt->pkt_ptr;
- } else
- return EPKTINVALPTR;
- icmp->icmp_id = htons(id);
- icmp->icmp_seq = htons(seqno);
- if (!cmask) {
- icmp->icmp_mask = htons(mask);
- } else {
- if (inet_aton(cmask, &inetaddr) != 0) {
- icmp->icmp_mask = inetaddr.s_addr;
- } else
- return EERRNO;
- }
- return 0;
-}
-
-int
-pkt_icmp_cksum(struct packet *pkt, unsigned int len)
-{
- struct icmp *icmp;
-
- if (!pkt)
- return EPKTINVALPTR;
-
- icmp = (struct icmp *) pkt->pkt_ptr;
- icmp->icmp_cksum = 0;
- icmp->icmp_cksum = in_cksum((unsigned short *)icmp, len);
- return 0;
-}
-
-int
-pkt_icmp_dest_unreach(struct packet *pkt, unsigned int unused)
-{
- struct icmp *icmp;
-
- if (pkt) {
- icmp = (struct icmp *)pkt->pkt_ptr;
- } else
- return EPKTINVALPTR;
- icmp->icmp_void = htons(unused);
- return 0;
-}
-
-int
-pkt_icmp_source_quench(struct packet *pkt, unsigned int unused)
-{
- struct icmp *icmp;
-
- if (pkt) {
- icmp = (struct icmp *)pkt->pkt_ptr;
- } else
- return EPKTINVALPTR;
- icmp->icmp_void = htons(unused);
- return 0;
-}
-
-int
-pkt_icmp_redirect(struct packet *pkt, unsigned int routerip, char *crouterip)
-{
- struct icmp *icmp;
- struct in_addr inetaddr;
-
- if (pkt) {
- icmp = (struct icmp *)pkt->pkt_ptr;
- } else {
- return EPKTINVALPTR;
- }
- if (crouterip) {
- if (inet_aton(crouterip, &inetaddr) != 0) {
- icmp->icmp_gwaddr = inetaddr;
- } else
- return EERRNO;
- } else {
- inetaddr.s_addr = htons(routerip);
- icmp->icmp_gwaddr = inetaddr;
- }
- return 0;
-}
-
-int
-pkt_icmp_echo(struct packet *pkt, unsigned short int id, unsigned short int seqno, void *data, size_t data_len)
-{
- struct icmp *icmp;
-
- if (pkt) {
- icmp = (struct icmp *) pkt->pkt_ptr;
- } else
- return EPKTINVALPTR;
- icmp->icmp_id = htons(id);
- icmp->icmp_seq = htons(seqno);
- if (data) {
- memcpy(icmp->icmp_data, data, data_len);
- }
- return 0;
-}
-
-int
-pkt_icmp_timestamp(struct packet *pkt, unsigned short int id, unsigned short int seqno, unsigned int ts_otime, unsigned int ts_rtime, unsigned int ts_ttime)
-{
- struct icmp *icmp;
-
- if (pkt)
- icmp = (struct icmp *) pkt->pkt_ptr;
- else
- return EPKTINVALPTR;
- icmp->icmp_id = htons(id);
- icmp->icmp_seq = htons(seqno);
- icmp->icmp_otime = htons(ts_otime);
- icmp->icmp_rtime = htons(ts_rtime);
- icmp->icmp_ttime = htons(ts_ttime);
- return 0;
-}
return 0;
}
-
-int
-pkt_ip_option_header(struct packet *pkt, unsigned char type, unsigned char len, unsigned char ptr, unsigned char oflw_flg, void *optval, size_t optlen)
-{
- unsigned char *vp;
-
- if (!pkt)
- return EPKTINVALPTR;
-
- vp = pkt->pkt_ptr;
- *vp = type;
- switch (type) {
- case PKT_IP_OPT_END:
- break;
- case PKT_IP_OPT_NOP:
- break;
- case PKT_IP_OPT_SEC:
- if ((pkt->pkt_pos + 2 + optlen) <= pkt->pkt_size) {
- *(vp+1) = len;
- memcpy((void*)(vp+2), optval, optlen);
- } else {
- return EPKTRANGE;
- }
- break;
- case PKT_IP_OPT_RR:
- case PKT_IP_OPT_LSRR:
- case PKT_IP_OPT_SSRR:
- case PKT_IP_OPT_SID:
- if ((pkt->pkt_pos + 3 + optlen) <= pkt->pkt_size) {
- *(vp+1) = len;
- *(vp+2) = ptr;
- memcpy((void*)(vp+3), optval, optlen);
- } else {
- return EPKTRANGE;
- }
- break;
- case PKT_IP_OPT_TS:
- if ((pkt->pkt_pos + 4 + optlen) <= pkt->pkt_size) {
- *(vp+1) = len;
- *(vp+2) = ptr;
- *(vp+3) = oflw_flg;
- memcpy((void*)(vp+4), optval, optlen);
- } else {
- return EPKTRANGE;
- }
- break;
- default:
- return EPKTUNKNOWNTYPE;
- }
- return PKTOK;
-}
-
-int
-pkt_ip_cksum(struct packet *pkt)
-{
- /*
- * checksum should be calculated by kernel
- * when we are using SOCK_RAW access.
- */
- struct ip *ip;
-
- if (!pkt)
- return EPKTINVALPTR;
-
- ip = (struct ip *) pkt->pkt_ptr;
- ip->ip_sum = 0;
- ip->ip_sum = in_cksum((unsigned short *)ip, sizeof(struct ip));
- return 0;
-}
int pkt_free(struct packet *pkt);
/* pointer movement */
-int pkt_set_actptr(struct packet *pkt, unsigned int bytepos);
int pkt_move_actptr(struct packet *pkt, int relmov);
-/* raw data */
-int pkt_add_systimestamp(struct packet *pkt);
-int pkt_add_data(struct packet *pkt, char *data, size_t data_len);
-int pkt_resize(struct packet *pkt, unsigned int newsize);
-
-/* socket operations */
-int pkt_socket_open(struct pkt_socket *sck, int type);
-int pkt_socket_close(struct pkt_socket *sck);
-int pkt_socket_prepare(struct pkt_socket *sck, char *daddr);
-int pkt_socket_setopt(struct pkt_socket *sck, int level, int optname, void *optval, socklen_t optlen);
-
-/* sending */
-int pkt_send(struct packet *pkt, struct pkt_socket *sck);
-
/* IP */
int pkt_ip_header(struct packet *pkt, unsigned int iphdr_len, unsigned int version, unsigned char tos, unsigned short int total_len, unsigned short int id, unsigned short int frag_off /* 3bit flag, 13bit offset */, unsigned char ttl, unsigned char protocol, unsigned short int cksum, unsigned int saddr, unsigned int daddr);
-int pkt_ip_cksum(struct packet *pkt);
-int pkt_ip_option_header(struct packet *pkt, unsigned char type, unsigned char len, unsigned char ptr, unsigned char oflw_flg, void *optval, size_t optlen);
/* TCP */
int pkt_tcp_header(struct packet *pkt, unsigned short int sport, unsigned short int dport, unsigned int seq, unsigned int ackseq, unsigned char headerlen, unsigned char reserved, unsigned char flags, unsigned short window, unsigned short int checksum, unsigned short int urgent);
int pkt_tcp_cksum(struct packet *pkt, char *saddr, char *daddr, unsigned int tcp_pkt_size);
int pkt_tcp_option(struct packet *pkt, unsigned char kind, unsigned char len, void *optval, size_t optlen);
-/* UDP */
-int pkt_udp_header(struct packet *pkt, unsigned short int sport, unsigned short int dport, unsigned short int udp_total_len, unsigned short int checksum);
-int pkt_udp_cksum(struct packet *pkt, char *saddr, char *daddr, unsigned int udp_total_len);
-
-/* ICMP */
-int pkt_icmp_header(struct packet *pkt, unsigned char type, unsigned char code, unsigned short int checksum);
-int pkt_icmp_cksum(struct packet *pkt, unsigned int len);
-int pkt_icmp_addr_mask(struct packet *pkt, unsigned short int id, unsigned short int seqno, unsigned int mask, char *cmask);
-int pkt_icmp_dest_unreach(struct packet *pkt, unsigned int unused);
-int pkt_icmp_source_quench(struct packet *pkt, unsigned int unused);
-int pkt_icmp_redirect(struct packet *pkt, unsigned int routerip, char *crouterip);
-int pkt_icmp_echo(struct packet *pkt, unsigned short int id, unsigned short int seqno, void *data, size_t data_len);
-int pkt_icmp_timestamp(struct packet *pkt, unsigned short int id, unsigned short int seqno, unsigned int ts_otime, unsigned int ts_rtime, unsigned int ts_ttime);
-
/* functions that might be useful and might be added some day ...
int pkt_shift_data(struct packet *pkt, unsigned int from, unsigned int to, unsigned int len);
int pkt_tcp_change_seqno(int rel_seq, int rel_ackseq);
+++ /dev/null
-/* $Id: misc.c,v 1.1 2005/12/12 18:14:22 nobunaga Exp $
-
-Copyright (C) 2002 Marc Kirchner <kirchner@stud.fh-heilbronn.de>
-
-This library 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 2.1 of the License, or (at your option) any later version.
-
-This library 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 Lesser General Public
-License along with this library; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-*/
-
-#include "libpal.h"
-
-/*
-<++doc++>
-@name int pkt_add_systimestamp(struct packet *pkt)
-@desc Adds a system timestamp (struct timeval) at the position where pkt->pkt_ptr points to.
-@param pkt packet into which a timestamp with the current system time will be added.
-<--doc-->
-*/
-int
-pkt_add_systimestamp(struct packet *pkt)
-{
- if (!pkt)
- return EPKTINVALPTR;
- if (pkt->pkt_size < (pkt->pkt_pos + sizeof(struct timeval)))
- return EPKTRANGE;
- if (gettimeofday((struct timeval *)pkt->pkt_ptr, NULL) == 0)
- return 0;
- else
- return EERRNO;
-}
-
return EPKTINVALPTR;
}
-/*
-<++doc++>
-@name int pkt_set_actptr(struct packet *pkt, unsigned int bytepos)
-@desc This function sets the active pointer position inside the packet.
-@param pkt the packet whose active ptr is to be set
-@param bytepos the byte position where to set the active ptr to, starting from 0
-<--doc-->
-*/
-
-int
-pkt_set_actptr(struct packet *pkt, unsigned int bytepos)
-{
- if (!pkt)
- return EPKTINVALPTR;
- if (bytepos > pkt->pkt_size) {
- return EPKTRANGE;
- } else {
- pkt->pkt_ptr = pkt->pkt + bytepos;
- return PKTOK;
- }
-}
-
/*
<++doc++>
@name int pkt_move_actptr(struct packet *pkt, int relmov)
return PKTOK;
}
}
-
-/*
-<++doc++>
-@name int pkt_add_data(struct packet *pkt, char *data, size_t data_len)
-@desc Adds supplied data at the current active ptr position of the given packet.This basically is a memcpy() wrapper function.
-@param pkt data will be written into this packet
-@param data a pointer to the data that shall be copied into the packet
-@param data_len the amount of data (in bytes) that will be copied
-<--doc-->
-*/
-int
-pkt_add_data(struct packet *pkt, char *data, size_t data_len)
-{
- if (!pkt || !data)
- return EPKTINVALPTR;
- if (pkt->pkt_size >= (pkt->pkt_pos + data_len)) {
- memcpy(pkt->pkt_ptr, data, data_len);
- return 0;
- } else
- return EPKTRANGE;
-}
-
-/*
-<++doc++>
-@name int pkt_resize(struct packet *pkt, unsigned int newsize)
-@desc The given packet will be resized to newsize
-@param pkt the packet to resize
-@param newsize the new size of the packet
-<--doc-->
-*/
-int
-pkt_resize(struct packet *pkt, unsigned int newsize)
-{
- unsigned char *newpkt;
-
- if (!pkt)
- return EPKTINVALPTR;
-
- if ((newpkt = (unsigned char *) malloc(newsize)) != NULL) {
- memset(newpkt, 0, newsize);
- memcpy(newpkt, pkt->pkt, (pkt->pkt_size < newsize ? pkt->pkt_size : newsize));
- pkt->pkt_size = newsize;
- pkt->pkt_ptr = newpkt;
- pkt->pkt_pos = 0;
- /* free old mem */
- free (pkt->pkt);
- pkt->pkt = newpkt;
- return 0;
- } else
- return EERRNO;
-}
+++ /dev/null
-/* $Id: socket.c,v 1.1 2005/12/12 18:14:22 nobunaga Exp $
-
-Copyright (C) 2002 Marc Kirchner <kirchner@stud.fh-heilbronn.de>
-
-This library 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 2.1 of the License, or (at your option) any later version.
-
-This library 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 Lesser General Public
-License along with this library; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-*/
-
-#include "libpal.h"
-
-/*
-<++doc++>
-@name int pkt_socket_open(struct pkt_socket *sck, int type)
-@desc Opens a packet socket. This is necessary to be able to send any packages.
-@param sck pointer to a pkt_socket structure
-@param type The type of the socket. Possible values are PKT_RAW (to open a raw socket. IP, TCP/UDP and application header have to be forged before sending) , PKT_STREAM, PKT_DGRAM. STREAM and DGRAM are supported by this function, but other function do not care.
-<--doc-->
-*/
-int
-pkt_socket_open(struct pkt_socket *sck, int type)
-{
- int proto;
- int iphdrincl = 1;
- int ret = 0;
-
- if (!sck)
- return EPKTINVALPTR;
-
- /* get mem for sockaddr structure */
- if ((sck->sckad = (struct sockaddr_in *) malloc (sizeof(struct sockaddr_in))) == NULL) {
- return -1;
- }
- sck->sckad_len = sizeof(struct sockaddr_in);
- memset(sck->sckad, 0, sck->sckad_len);
-
- /* except for raw sockets, proto is set to 0 */
- /* (Stevens, UNP 2nd ed., 1998) */
- switch (type) {
- case PKT_RAW:
- proto = IPPROTO_RAW;
- break;
- default:
- proto = 0;
- break;
- }
- if ((sck->rawfd = socket(AF_INET, type, proto)) == -1) {
- return -1;
- }
- if (type == PKT_RAW) {
- if ((ret = setsockopt(sck->rawfd, IPPROTO_IP, IP_HDRINCL, (const void *) &iphdrincl, sizeof(iphdrincl))) < 0) {
- return -1;
- }
- }
- return 0;
-}
-
-
-/*
-<++doc++>
-@name int pkt_socket_close(struct pkt_socket *sck)
-@desc Closes a packet socket and frees used memory.
-@param sck pointer to a pkt_socket structure
-<--doc-->
-*/
-int
-pkt_socket_close(struct pkt_socket *sck)
-{
- if (!sck)
- return EPKTINVALPTR;
- close(sck->rawfd);
- free(sck->sckad);
- sck->sckad=NULL;
- return 0;
-}
-
-/*
-<++doc++>
-@name int pkt_socket_prepare(struct pkt_socket *sck, char *daddr)
-@desc this function is necessary to enable the kernel to determine the correct outgoing interface
-@param sck pointer to a pkt_socket structure
-@param daddr dotted-decimal destination IP address
-<--doc-->
-*/
-int
-pkt_socket_prepare(struct pkt_socket *sck, char *daddr)
-{
- /*
- * this is necessary for the kernel to determine outgoing
- * interface.
- */
-
- int ret = 0;
-
- if (!sck || !daddr)
- return EPKTINVALPTR;
-
- /* set up sockaddr struct */
- memset(sck->sckad, 0, sck->sckad_len);
- if ((ret = inet_pton(AF_INET, daddr, &(sck->sckad->sin_addr))) == 0) {
- return -1;
- }
- sck->sckad->sin_family = AF_INET;
-
- /*
- * i dont think we need to set the dest port...
- */
- return 0;
-}
-
-/*
-<++doc++>
-@name int pkt_socket_setopt(struct pkt_socket *sck, int level, int optname, void *optval, socklen_t optlen)
-@desc this is basically a wrapper function for setsockopt(2)
-@param sck pointer to a pkt_socket structure
-@param level level the socket option will apply to (should be SOL_SOCKET)
-@param optname option name, see sys/socket.h for values
-@param optval new option value (for boolean options: 0=false)
-@param optlen option value size (this is a value-result parameter!)
-<--doc-->
-*/
-int
-pkt_socket_setopt(struct pkt_socket *sck, int level,
- int optname, void *optval, socklen_t optlen)
-{
- if (!sck)
- return EPKTINVALPTR;
- return (setsockopt(sck->rawfd, level, optname, optval, optlen));
-}
-
-
-/*
-<++doc++>
-@name int pkt_send(struct packet *pkt, struct pkt_socket *sck)
-@desc sends the packet pkt unsing the socket sck
-@param pkt pointer to a packet structure
-@param sck pointer to a pkt_socket structure
-<--doc-->
-*/
-int
-pkt_send(struct packet *pkt, struct pkt_socket *sck)
-{
- int ret = 0;
-
- if (!pkt || !sck)
- return EPKTINVALPTR;
-
- /* no sendto-flags support */
- if ((ret = sendto(sck->rawfd, pkt->pkt, pkt->pkt_size, 0, (struct sockaddr *) sck->sckad, sck->sckad_len)) == -1) {
- return -1;
- }
- return 0;
-}
+++ /dev/null
-/* $Id: udp.c,v 1.1 2005/12/12 18:14:22 nobunaga Exp $
-
-Copyright (C) 2002 Marc Kirchner <kirchner@stud.fh-heilbronn.de>
-
-This library 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 2.1 of the License, or (at your option) any later version.
-
-This library 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 Lesser General Public
-License along with this library; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-*/
-
-#include "libpal.h"
-#include "types.h"
-
-int
-pkt_udp_header(struct packet *pkt, unsigned short int sport, unsigned short int dport, unsigned short int udp_total_len, unsigned short int checksum)
-{
- struct udphdr *udp;
-
- if (!pkt)
- return EPKTINVALPTR;
- if (pkt->pkt_size >= (pkt->pkt_pos + sizeof(struct udphdr))) {
- udp = (struct udphdr *) pkt->pkt_ptr;
- udp->source = htons(sport);
- udp->dest = htons(dport);
- udp->len = htons(udp_total_len);
- udp->check = htons(checksum);
- return 0;
- } else
- return EPKTRANGE;
-}
-
-int
-pkt_udp_cksum(struct packet *pkt, char *saddr, char *daddr,
- unsigned int udp_total_len)
-{
- char *tosum;
- struct pseudohdr *psh;
- struct udphdr *udp;
- unsigned short int check=0;
- struct in_addr addr;
-
- if (!pkt || !saddr || !daddr)
- return EPKTINVALPTR;
-
- if ((udp_total_len + pkt->pkt_pos) > pkt->pkt_size -1)
- return EPKTRANGE;
-
- if ((tosum = (char *) malloc(udp_total_len+sizeof(struct pseudohdr))) != NULL) {
- memset(tosum, 0, udp_total_len+sizeof(struct pseudohdr));
- psh = (struct pseudohdr *) tosum;
- udp = (struct udphdr *) pkt->pkt_ptr;
-
- udp->check = 0;
-
- if (inet_pton(AF_INET, saddr, &addr) < 0)
- return EERRNO;
- psh->saddr = addr.s_addr;
- if (inet_pton(AF_INET, daddr, &addr) < 0)
- return EERRNO;
- psh->daddr = addr.s_addr;
- psh->zero = 0x00;
- psh->protocol = IPPROTO_UDP;
- psh->length = htons(udp_total_len);
-
- memcpy(tosum + sizeof(struct pseudohdr), udp, udp_total_len);
- check = in_cksum((unsigned short *)tosum, udp_total_len + sizeof(struct pseudohdr));
- /* _no_ call to htons(), because tosum is in network byte order */
- udp->check = check == 0 ? 0xffff : check;
- free(tosum);
- return 0;
- } else
- return EERRNO;
-}
return true;
}
-std::string OI2String(OBJECT_IDENTIFIER_t * oi)
-{
-std::string res;
-
-int arcs[1024];
-int count = OBJECT_IDENTIFIER_get_arcs(oi, arcs, sizeof(arcs[0]), 1024);
-
-if (count > 1024)
- return "";
-
-for (int i = 0; i < count; ++i)
- {
- res += ".";
- std::string arc;
- strprintf(&arc, "%d", arcs[i]);
- res += arc;
- }
-
-return res;
-}
-
bool SendOpenPDU(int fd)
{
const char * description = "Stg SMUX Plugin";
#include "stg/GetResponse-PDU.h"
bool String2OI(const std::string & str, OBJECT_IDENTIFIER_t * oi);
-std::string OI2String(OBJECT_IDENTIFIER_t * oi);
bool SendOpenPDU(int fd);
bool SendClosePDU(int fd);
bool SendRReqPDU(int fd);
continue;
}
- r = sscanf(str,"%s %s %s", tp, ta, td);
+ r = sscanf(str,"%100s %100s %100s", tp, ta, td);
if (r != 3)
{
printfd(__FILE__, "TRAFFCOUNTER_IMPL::ReadRules() - Error in file '%s' at line %d. There must be 3 parameters.\n", rulesFileName.c_str(), lineNumber);
signed long accum;
ssize_t wrote = 0;
char *p;
- int ret;
/*
* Advance buf pointer until the start of the value's body.
if((size_t)(buf_end - buf) <= sizeof(accum)) {
const asn_INTEGER_enum_map_t *el;
size_t scrsize;
+ int ret;
char *scr;
if(buf == buf_end) {
asn_INTEGER_specifics_t *specs = (asn_INTEGER_specifics_t *)td->specifics;
asn_enc_rval_t er;
long native, value;
- asn_per_constraint_t *ct;
+ asn_per_constraint_t *ct = NULL;
int inext = 0;
asn_INTEGER_enum_map_t key;
asn_INTEGER_enum_map_t *kf;
}
value = kf - specs->value2enum;
- if(ct->range_bits >= 0) {
+ if(ct && ct->range_bits >= 0) {
int cmpWith = specs->extension
? specs->extension - 1 : specs->map_count;
if(value >= cmpWith)
inext = 1;
}
- if(ct->flags & APC_EXTENSIBLE) {
+ if(ct && ct->flags & APC_EXTENSIBLE) {
if(per_put_few_bits(po, inext, 0))
_ASN_ENCODE_FAILED;
ct = 0;
NativeInteger_print(asn_TYPE_descriptor_t *td, const void *sptr, int ilevel,
asn_app_consume_bytes_f *cb, void *app_key) {
const long *native = (const long *)sptr;
- char scratch[32]; /* Enough for 64-bit int */
- int ret;
(void)td; /* Unused argument */
(void)ilevel; /* Unused argument */
if(native) {
- ret = snprintf(scratch, sizeof(scratch), "%ld", *native);
+ char scratch[32]; /* Enough for 64-bit int */
+ int ret = snprintf(scratch, sizeof(scratch), "%ld", *native);
assert(ret > 0 && (size_t)ret < sizeof(scratch));
return (cb(scratch, ret, app_key) < 0) ? -1 : 0;
} else {
asn_app_consume_bytes_f *cb, void *app_key) {
char scratch[64]; /* Conservative estimate */
unsigned long accum; /* Bits accumulator */
- char *p; /* Position in the scratch buffer */
if(OBJECT_IDENTIFIER_get_single_arc(arcbuf, arclen, add,
&accum, sizeof(accum)))
if(accum) {
ssize_t len;
+ char *p = scratch + sizeof(scratch); /* Position in the scratch buffer */
- /* Fill the scratch buffer in reverse. */
- p = scratch + sizeof(scratch);
for(; accum; accum /= 10)
*(--p) = (char)(accum % 10) + 0x30; /* Put a digit */
char *p = scratch;
uint8_t *buf;
uint8_t *end;
- size_t i;
if(!st || !st->buf)
_ASN_ENCODE_FAILED;
_ASN_CALLBACK(scratch, p-scratch); /* Dump the rest */
er.encoded += p - scratch;
} else {
+ size_t i;
for(i = 0; buf < end; buf++, i++) {
if(!(i % 16) && (i || st->size > 16)) {
_ASN_CALLBACK(scratch, p-scratch);
asn_enc_rval_t er;
int ct_extensible = ct->flags & APC_EXTENSIBLE;
int inext = 0; /* Lies not within extension root */
- int sizeinunits = st->size;
+ int sizeinunits = 0;
const uint8_t *buf;
int ret;
if(!st || !st->buf)
_ASN_ENCODE_FAILED;
+ sizeinunits = st->size;
if(unit_bits == 1) {
ASN_DEBUG("BIT STRING of %d bytes, %d bits unused",
void
OCTET_STRING_free(asn_TYPE_descriptor_t *td, void *sptr, int contents_only) {
OCTET_STRING_t *st = (OCTET_STRING_t *)sptr;
- asn_OCTET_STRING_specifics_t *specs = td->specifics
+ asn_OCTET_STRING_specifics_t *specs = td && td->specifics
? (asn_OCTET_STRING_specifics_t *)td->specifics
: &asn_DEF_OCTET_STRING_specs;
asn_struct_ctx_t *ctx = (asn_struct_ctx_t *)
ber_skip_length(asn_codec_ctx_t *opt_codec_ctx,
int _is_constructed, const void *ptr, size_t size) {
ber_tlv_len_t vlen; /* Length of V in TLV */
- ssize_t tl; /* Length of L in TLV */
ssize_t ll; /* Length of L in TLV */
size_t skip;
ber_tlv_tag_t tag;
/* Fetch the tag */
- tl = ber_fetch_tag(ptr, size, &tag);
+ ssize_t tl = ber_fetch_tag(ptr, size, &tag);
if(tl <= 0) return tl;
ll = ber_skip_length(opt_codec_ctx,
void
CHOICE_free(asn_TYPE_descriptor_t *td, void *ptr, int contents_only) {
- asn_CHOICE_specifics_t *specs = (asn_CHOICE_specifics_t *)td->specifics;
+ asn_CHOICE_specifics_t *specs = td ? (asn_CHOICE_specifics_t *)td->specifics : NULL;
int present;
if(!td || !ptr)
ssize_t ch_size; /* Chunk size */
xer_check_tag_e tcv; /* Tag check value */
asn_TYPE_member_t *elm;
- int n;
/*
* Go inside the inner member of a sequence.
edx_end = edx + elements[edx].optional + 1;
if(edx_end > td->elements_count)
edx_end = td->elements_count;
+ int n;
for(n = edx; n < edx_end; n++) {
elm = &td->elements[n];
tcv = xer_check_tag(buf_ptr,
nelems = uper_get_length(pd,
ct ? ct->effective_bits : -1, &repeat);
ASN_DEBUG("Got to decode %d elements (eff %d)",
- (int)nelems, (int)ct ? ct->effective_bits : -1);
+ (int)nelems, ct ? ct->effective_bits : -1);
if(nelems < 0) _ASN_DECODE_STARVED;
}
ASN_DEBUG("Failed to add element into %s",
td->name);
/* Fall through */
- rv.code == RC_FAIL;
+ rv.code = RC_FAIL;
} else {
ASN_DEBUG("Failed decoding %s of %s (SET OF)",
elm->type->name, td->name);