Search

'CODE'에 해당되는 글 10건

  1. 2021.04.22 RIFF AudioEncoding Values
  2. 2017.12.27 Get Audio Device List
  3. 2016.09.20 Java JNetPcap Library Packet Capture
  4. 2016.09.19 openssl AES encrypt (AES_ctr128_encrypt)
  5. 2016.09.06 MFC Alert MessageBox2
  6. 2016.03.07 Winpcap Test 04
  7. 2016.03.07 Winpcap Test 03
  8. 2016.03.07 Winpcap Test 01
  9. 2013.05.02 아스키코드표
  10. 2013.04.29 Android Battery Monitor

RIFF AudioEncoding Values

Programming/C,CPP,CS 2021. 4. 22. 15:50 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

These "TwoCC" audio encoding codes are used in RIFF and ASF files.

 

 

 

 

www.bibliotecacpa.org.ar/greenstone/perllib/cpan/Image/ExifTool/RIFF.pm

 

Get Audio Device List

Programming/C# 2017. 12. 27. 11:02 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

Get Audio Device List




using System.Management;


        public void getAudioDevice()
        {
            ManagementObjectSearcher objSearcher = new ManagementObjectSearcher("SELECT * FROM Win32_SoundDevice");

            ManagementObjectCollection objCollection = objSearcher.Get();

            foreach (ManagementObject obj in objCollection)
            {
                String str = "";
                foreach (PropertyData property in obj.Properties)
                {
                    str += String.Format("{0}:{1}\n", property.Name, property.Value);
                }
                Console.Out.WriteLine(str + "\n\n");
            }
        }





참조 : https://stackoverflow.com/questions/1525320/how-to-enumerate-audio-out-devices-in-c-sharp

Java JNetPcap Library Packet Capture

Programming/JNetPcap 2016. 9. 20. 13:46 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

Java JNetPcap Library Packet Capture 


pcap File




테스트 환경 : Win7 64bit, Eclipse, Java 1.8



이클립스와


자바는 설치되어있다고 가정합니다.





JNetPcap 라이브러리 다운로드


http://jnetpcap.com/download



저는 x84_64



압축을 풀면





jnetpcap.jar, jnetpcap.dll



두 개의 파일이 보입니다.



1. jnetpcap.jar 은 Eclipse 프로젝트에서 참조 할 수 있도록






Package Explorer > Properties > Java Build Path > Libraries > Add JARs 나 Add External JARs 로 추가하여 줍니다.



다운받은 경로보다는


해당 프로젝트 Eclipse Workspace 내에 두는것을 추천합니다.




한글 경로 때문에 안되는 경우도 있습니다,



2. jnetpcap.dll





C:\Windows\System32 경로에 jnetpcap.dll 파일을 복사하여 줍니다.









이제 설정은 끝났습니다.




테스트 코드는 다음과 같습니다.










import java.io.File;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;

import org.jnetpcap.ByteBufferHandler;
import org.jnetpcap.Pcap;
import org.jnetpcap.PcapDumper;
import org.jnetpcap.PcapHeader;
import org.jnetpcap.PcapIf;

public class Test1 {
	public static void main(String[] args) {
		// pcap.loop(x, dumpHandler, dumper); x 개 패킷을
		// String ofile = "tmp-capture-file.cap"; tmp-capture-file.cap 파일로 저장


		List alldevs = new ArrayList(); // Will be filled with
														// NICs
		StringBuilder errbuf = new StringBuilder(); // For any error msgs

		/***************************************************************************
		 * First get a list of devices on this system
		 **************************************************************************/
		int r = Pcap.findAllDevs(alldevs, errbuf);
		if (r == Pcap.NOT_OK || alldevs.isEmpty()) {
			System.err.printf("Can't read list of devices, error is %s\n", errbuf.toString());
			return;
		}
		PcapIf device = alldevs.get(0); // We know we have atleast 1 device

		/***************************************************************************
		 * Second we open up the selected device
		 **************************************************************************/
		int snaplen = 64 * 1024; // Capture all packets, no trucation
		int flags = Pcap.MODE_PROMISCUOUS; // capture all packets
		int timeout = 10 * 1000; // 10 seconds in millis
		Pcap pcap = Pcap.openLive(device.getName(), snaplen, flags, timeout, errbuf);
		if (pcap == null) {
			System.err.printf("Error while opening device for capture: %s\n", errbuf.toString());
			return;
		}

		/***************************************************************************
		 * Third we create a PcapDumper and associate it with the pcap capture
		 ***************************************************************************/
		String ofile = "tmp-capture-file.cap";
		PcapDumper dumper = pcap.dumpOpen(ofile); // output file

		/***************************************************************************
		 * Fouth we create a packet handler which receives packets and tells the
		 * dumper to write those packets to its output file
		 **************************************************************************/
		ByteBufferHandler dumpHandler = new ByteBufferHandler() {

			public void nextPacket(PcapHeader arg0, ByteBuffer arg1, PcapDumper arg2) {
				// TODO Auto-generated method stub
				dumper.dump(arg0, arg1);
			}
		};

		/***************************************************************************
		 * Fifth we enter the loop and tell it to capture 10 packets. We pass in
		 * the dumper created in step 3
		 **************************************************************************/
		pcap.loop(10, dumpHandler, dumper);

		File file = new File(ofile);
		System.out.printf("%s file has %d bytes in it!\n", ofile, file.length());

		/***************************************************************************
		 * Last thing to do is close the dumper and pcap handles
		 **************************************************************************/
		dumper.close(); // Won't be able to delete without explicit close
		pcap.close();

		if (file.exists()) {
			// file.delete(); // Cleanup
		}	
	}
}


'Programming > JNetPcap' 카테고리의 다른 글

Java JNetPcap Library Packet Analytics  (0) 2016.09.20

openssl AES encrypt (AES_ctr128_encrypt)

Programming/C,CPP,CS 2016. 9. 19. 08:50 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

openssl AES encrypt (AES_ctr128_encrypt)



Sample Class













AESCTR.cppAESCTR.h


MFC Alert MessageBox2

Programming/MFC 2016. 9. 6. 10:47 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

      int MessageBox(
   LPCTSTR lpszText,
   LPCTSTR lpszCaption = NULL,
   UINT nType = MB_OK 
);

lpszText

가리키는 있는 CString 개체 또는 표시 되는 메시지에 포함 된 null로 끝나는 문자열입니다.

lpszCaption

가리키는 있는 CString 개체 또는 null로 끝나는 문자열에 대 한 캡션을 메시지 상자를 사용할 수 있습니다. 경우 lpszCaption  NULL, 기본 캡션을 "오류"를 사용 합니다.

nType

콘텐츠 및 메시지 상자의 동작을 지정합니다.


전역 함수 사용 AfxMessageBox 응용 프로그램에서 메시지 상자를 구현 하려면이 멤버 함수를 대신 합니다.

다음은 메시지 상자에 사용할 수 있는 다양 한 시스템 아이콘입니다.

중지(x) 아이콘

MB_ICONHANDMB_ICONSTOP, 및 MB_ICONERROR

도움말(?) 아이콘

MB_ICONQUESTION

중요(!) 아이콘

MB_ICONEXCLAMATION 및 MB_ICONWARNING

정보(i) 아이콘

MB_ICONASTERISK 및 MB_ICONINFORMATION









void CMainFrame::OnDisplayErrorMessage()
{
   // This displays a message box with the title "Error"
   // and the message "Help, Something went wrong."
   // The error icon is displayed in the message box, along with
   // an OK button.
   MessageBox(_T("Help, Something went wrong."), _T("Error"), 
      MB_ICONERROR | MB_OK);
}




'Programming > MFC' 카테고리의 다른 글

MFC Dialog Modal  (0) 2016.09.22
MFC Modal and Modeless Dialog Boxes  (0) 2016.09.06
MFC Alert MessageBox  (0) 2016.09.06
MFC Drag And Drop FileName 만 추출  (0) 2016.08.30
MFC File Icon Drag and Drop  (0) 2016.08.30

Winpcap Test 04

Programming/C,CPP,CS 2016. 3. 7. 09:49 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

응용


02,03 Test 를 합친다.


03 에서의 목록으로는 어떤 디바이스가 내가 캡쳐할 디바이스인지를 구분하기가 어렵다.


02에서의 상세정보를 활용하여 정리한다.



 

/*

* Copyright (c) 1999 - 2005 NetGroup, Politecnico di Torino (Italy)

* Copyright (c) 2005 - 2006 CACE Technologies, Davis (California)

* All rights reserved.

*

* Redistribution and use in source and binary forms, with or without

* modification, are permitted provided that the following conditions

* are met:

*

* 1. Redistributions of source code must retain the above copyright

* notice, this list of conditions and the following disclaimer.

* 2. Redistributions in binary form must reproduce the above copyright

* notice, this list of conditions and the following disclaimer in the

* documentation and/or other materials provided with the distribution.

* 3. Neither the name of the Politecnico di Torino, CACE Technologies 

* nor the names of its contributors may be used to endorse or promote 

* products derived from this software without specific prior written 

* permission.

*

* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS

* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT

* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR

* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT

* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,

* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT

* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,

* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY

* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT

* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE

* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

*

*/


#include <stdio.h>


#include "pcap.h"


#ifndef WIN32

#include <sys/socket.h>

#include <netinet/in.h>

#else

#include <winsock.h>

#endif



// Function prototypes

void ifprint(pcap_if_t *d);

char *iptos(u_long in);

char* ip6tos(struct sockaddr *sockaddr, char *address, int addrlen);

void packet_handler(u_char *param, const struct pcap_pkthdr *header, const u_char *pkt_data);



int main()

{

pcap_if_t *alldevs;

pcap_if_t *d;

char errbuf[PCAP_ERRBUF_SIZE+1];

char source[PCAP_ERRBUF_SIZE+1] = {'0'};

int inum;

int i = 0;

pcap_t *adhandle;



if (pcap_findalldevs_ex(source, NULL, &alldevs, errbuf) == -1)

{

fprintf(stderr,"Error in pcap_findalldevs: %s\n",errbuf);

exit(1);

}


/* Scan the list printing every entry */

for(d=alldevs;d;d=d->next)

{

ifprint(d);

i++;

}


printf("Enter the interface number (1-%d):",i);

scanf_s("%d", &inum);



if(inum < 1 || inum > i)

{

printf("\nInterface number out of range.\n");

/* Free the device list */

pcap_freealldevs(alldevs);

return -1;

}


/* Jump to the selected adapter */

for(d=alldevs, i=0; i< inum-1 ;d=d->next, i++);





/* Open the device */

if ( (adhandle= pcap_open(d->name,          // name of the device

65536,            // portion of the packet to capture

// 65536 guarantees that the whole packet will be captured on all the link layers

PCAP_OPENFLAG_PROMISCUOUS,    // promiscuous mode

1000,             // read timeout

NULL,             // authentication on the remote machine

errbuf            // error buffer

) ) == NULL)

{

fprintf(stderr,"\nUnable to open the adapter. %s is not supported by WinPcap\n", d->name);

/* Free the device list */

pcap_freealldevs(alldevs);

return -1;

}


printf("\nlistening on %s...\n", d->description);


/* At this point, we don't need any more the device list. Free it */

pcap_freealldevs(alldevs);


/* start the capture */

pcap_loop(adhandle, 0, packet_handler, NULL);



return 1;

}




/* Print all the available information on the given interface */

void ifprint(pcap_if_t *d)

{

pcap_addr_t *a;

char ip6str[128];


/* Name */

printf("\tName: %s\n",d->name);


/* Description */

if (d->description)

printf("\tDescription: %s\n",d->description);


/* Loopback Address*/

printf("\tLoopback: %s\n",(d->flags & PCAP_IF_LOOPBACK)?"yes":"no");


/* IP addresses */

for(a=d->addresses;a;a=a->next) {

if(a->addr->sa_family != AF_INET)

continue;


printf("\tAddress Family Name: AF_INET\n");

if (a->addr)

printf("\tAddress: %s\n",iptos(((struct sockaddr_in *)a->addr)->sin_addr.s_addr));

if (a->netmask)

printf("\tNetmask: %s\n",iptos(((struct sockaddr_in *)a->netmask)->sin_addr.s_addr));

if (a->broadaddr)

printf("\tBroadcast Address: %s\n",iptos(((struct sockaddr_in *)a->broadaddr)->sin_addr.s_addr));

if (a->dstaddr)

printf("\tDestination Address: %s\n",iptos(((struct sockaddr_in *)a->dstaddr)->sin_addr.s_addr));

}

printf("\n");

}




/* From tcptraceroute, convert a numeric IP address to a string */

#define IPTOSBUFFERS    12

char *iptos(u_long in)

{

static char output[IPTOSBUFFERS][3*4+3+1];

static short which;

u_char *p;


p = (u_char *)&in;

which = (which + 1 == IPTOSBUFFERS ? 0 : which + 1);

_snprintf_s(output[which], sizeof(output[which]), sizeof(output[which]),"%d.%d.%d.%d", p[0], p[1], p[2], p[3]);

return output[which];

}


char* ip6tos(struct sockaddr *sockaddr, char *address, int addrlen)

{

socklen_t sockaddrlen;


#ifdef WIN32

sockaddrlen = sizeof(struct sockaddr_in6);

#else

sockaddrlen = sizeof(struct sockaddr_storage);

#endif



if(getnameinfo(sockaddr, 

sockaddrlen, 

address, 

addrlen, 

NULL, 

0, 

NI_NUMERICHOST) != 0) address = NULL;


return address;

}


/* Callback function invoked by libpcap for every incoming packet */

void packet_handler(u_char *param, const struct pcap_pkthdr *header, const u_char *pkt_data)

{

struct tm ltime;

char timestr[16];

time_t local_tv_sec;


/*

* unused variables

*/

(VOID)(param);

(VOID)(pkt_data);


/* convert the timestamp to readable format */

local_tv_sec = header->ts.tv_sec;

localtime_s(&ltime, &local_tv_sec);

strftime( timestr, sizeof timestr, "%H:%M:%S", &ltime);


printf("%s,%.6d len:%d\n", timestr, header->ts.tv_usec, header->len);


}


'Programming > C,CPP,CS' 카테고리의 다른 글

Winpcap Test 06  (0) 2016.03.07
Winpcap Test 05  (0) 2016.03.07
Winpcap Test 03  (0) 2016.03.07
Winpcap Test 02  (0) 2016.03.07
Winpcap Test 01  (0) 2016.03.07

Winpcap Test 03

Programming/C,CPP,CS 2016. 3. 7. 09:11 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

Opening an adapter and capturing the packets


#include "pcap.h"

/* prototype of the packet handler */
void packet_handler(u_char *param, const struct pcap_pkthdr *header, const u_char *pkt_data);

int main()
{
pcap_if_t *alldevs;
pcap_if_t *d;
int inum;
int i=0;
pcap_t *adhandle;
char errbuf[PCAP_ERRBUF_SIZE];
    
    /* Retrieve the device list on the local machine */
    if (pcap_findalldevs_ex(PCAP_SRC_IF_STRING, NULL, &alldevs, errbuf) == -1)
    {
        fprintf(stderr,"Error in pcap_findalldevs: %s\n", errbuf);
        exit(1);
    }
    
    /* Print the list */
    for(d=alldevs; d; d=d->next)
    {
        printf("%d. %s", ++i, d->name);
        if (d->description)
            printf(" (%s)\n", d->description);
        else
            printf(" (No description available)\n");
    }
    
    if(i==0)
    {
        printf("\nNo interfaces found! Make sure WinPcap is installed.\n");
        return -1;
    }
    
    printf("Enter the interface number (1-%d):",i);
    scanf_s("%d", &inum);
    
    if(inum < 1 || inum > i)
    {
        printf("\nInterface number out of range.\n");
        /* Free the device list */
        pcap_freealldevs(alldevs);
        return -1;
    }
    
    /* Jump to the selected adapter */
    for(d=alldevs, i=0; i< inum-1 ;d=d->next, i++);
    
    /* Open the device */
    if ( (adhandle= pcap_open(d->name,          // name of the device
                              65536,            // portion of the packet to capture
                                                // 65536 guarantees that the whole packet will be captured on all the link layers
                              PCAP_OPENFLAG_PROMISCUOUS,    // promiscuous mode
                              1000,             // read timeout
                              NULL,             // authentication on the remote machine
                              errbuf            // error buffer
                              ) ) == NULL)
    {
        fprintf(stderr,"\nUnable to open the adapter. %s is not supported by WinPcap\n", d->name);
        /* Free the device list */
        pcap_freealldevs(alldevs);
        return -1;
    }
    
    printf("\nlistening on %s...\n", d->description);
    
    /* At this point, we don't need any more the device list. Free it */
    pcap_freealldevs(alldevs);
    
    /* start the capture */
    pcap_loop(adhandle, 0, packet_handler, NULL);
    
    return 0;
}


/* Callback function invoked by libpcap for every incoming packet */
void packet_handler(u_char *param, const struct pcap_pkthdr *header, const u_char *pkt_data)
{
    struct tm ltime;
    char timestr[16];
    time_t local_tv_sec;

    /*
     * unused variables
     */
    (VOID)(param);
    (VOID)(pkt_data);

    /* convert the timestamp to readable format */
    local_tv_sec = header->ts.tv_sec;
    localtime_s(&ltime, &local_tv_sec);
    strftime( timestr, sizeof timestr, "%H:%M:%S", &ltime);
    
    printf("%s,%.6d len:%d\n", timestr, header->ts.tv_usec, header->len);
    
}




'Programming > C,CPP,CS' 카테고리의 다른 글

Winpcap Test 05  (0) 2016.03.07
Winpcap Test 04  (0) 2016.03.07
Winpcap Test 02  (0) 2016.03.07
Winpcap Test 01  (0) 2016.03.07
CPP 2015-01-15 수업내용 정리  (0) 2015.01.15

Winpcap Test 01

Programming/C,CPP,CS 2016. 3. 7. 08:50 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

Winpcap Test 01



Download WinPcap 4.1.2 Developer's Pack

http://www.winpcap.org/devel.htm



C/C++ -> Genenral -> Additional Include Directories : WpdPack/WpdPack/Include


Linker -> General -> Additional Library Directories : WpdPack/WpdPack/Lib


Linker -> Input -> Addtional Dependencies : wpcap.lib Packet.lib


C/C++ -> Preprocessor -> PreProcessor Definitions : HAVE_REMOTE


sample Code

/* Copyright (c) 1999 - 2005 NetGroup, Politecnico di Torino (Italy)

 * Copyright (c) 2005 - 2006 CACE Technologies, Davis (California)

 * All rights reserved.

 *

 * Redistribution and use in source and binary forms, with or without

 * modification, are permitted provided that the following conditions

 * are met:

 *

 * 1. Redistributions of source code must retain the above copyright

 * notice, this list of conditions and the following disclaimer.

 * 2. Redistributions in binary form must reproduce the above copyright

 * notice, this list of conditions and the following disclaimer in the

 * documentation and/or other materials provided with the distribution.

 * 3. Neither the name of the Politecnico di Torino, CACE Technologies 

 * nor the names of its contributors may be used to endorse or promote 

 * products derived from this software without specific prior written 

 * permission.

 *

 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS

 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT

 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR

 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT

 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,

 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT

 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,

 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY

 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT

 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE

 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

 *

 */



#include <stdlib.h>

#include <stdio.h>


//

// NOTE: remember to include WPCAP and HAVE_REMOTE among your

// preprocessor definitions.

//


#include <pcap.h>


#define LINE_LEN 16


int main(int argc, char **argv)

{   

pcap_if_t *alldevs, *d;

pcap_t *fp;

u_int inum, i=0;

char errbuf[PCAP_ERRBUF_SIZE];

int res;

struct pcap_pkthdr *header;

const u_char *pkt_data;


    printf("pktdump_ex: prints the packets of the network using WinPcap.\n");

    printf("   Usage: pktdump_ex [-s source]\n\n"

           "   Examples:\n"

           "      pktdump_ex -s file://c:/temp/file.acp\n"

           "      pktdump_ex -s rpcap://\\Device\\NPF_{C8736017-F3C3-4373-94AC-9A34B7DAD998}\n\n");


    if(argc < 3)

    {


        printf("\nNo adapter selected: printing the device list:\n");

        /* The user didn't provide a packet source: Retrieve the local device list */

        if (pcap_findalldevs_ex(PCAP_SRC_IF_STRING, NULL, &alldevs, errbuf) == -1)

        {

            fprintf(stderr,"Error in pcap_findalldevs_ex: %s\n", errbuf);

            return -1;

        }

        

        /* Print the list */

        for(d=alldevs; d; d=d->next)

        {

            printf("%d. %s\n    ", ++i, d->name);


            if (d->description)

                printf(" (%s)\n", d->description);

            else

                printf(" (No description available)\n");

        }

        

        if (i==0)

        {

            fprintf(stderr,"No interfaces found! Exiting.\n");

            return -1;

        }

        

        printf("Enter the interface number (1-%d):",i);

        scanf_s("%d", &inum);

        

        if (inum < 1 || inum > i)

        {

            printf("\nInterface number out of range.\n");


            /* Free the device list */

            pcap_freealldevs(alldevs);

            return -1;

        }

        

        /* Jump to the selected adapter */

        for (d=alldevs, i=0; i< inum-1 ;d=d->next, i++);

        

        /* Open the device */

        if ( (fp= pcap_open(d->name,

                            100 /*snaplen*/,

                            PCAP_OPENFLAG_PROMISCUOUS /*flags*/,

                            20 /*read timeout*/,

                            NULL /* remote authentication */,

                            errbuf)

                            ) == NULL)

        {

            fprintf(stderr,"\nError opening adapter\n");

            return -1;

        }

    }

    else 

    {

        // Do not check for the switch type ('-s')

        if ( (fp= pcap_open(argv[2],

                            100 /*snaplen*/,

                            PCAP_OPENFLAG_PROMISCUOUS /*flags*/,

                            20 /*read timeout*/,

                            NULL /* remote authentication */,

                            errbuf)

                            ) == NULL)

        {

            fprintf(stderr,"\nError opening source: %s\n", errbuf);

            return -1;

        }

    }


    /* Read the packets */

    while((res = pcap_next_ex( fp, &header, &pkt_data)) >= 0)

    {


        if(res == 0)

            /* Timeout elapsed */

            continue;


        /* print pkt timestamp and pkt len */

        printf("%ld:%ld (%ld)\n", header->ts.tv_sec, header->ts.tv_usec, header->len);          

        

        /* Print the packet */

        for (i=1; (i < header->caplen + 1 ) ; i++)

        {

            printf("%.2x ", pkt_data[i-1]);

            if ( (i % LINE_LEN) == 0) printf("\n");

        }

        

        printf("\n\n");     

    }


    if(res == -1)

    {

        fprintf(stderr, "Error reading the packets: %s\n", pcap_geterr(fp));

        return -1;

    }


    return 0;

}


'Programming > C,CPP,CS' 카테고리의 다른 글

Winpcap Test 03  (0) 2016.03.07
Winpcap Test 02  (0) 2016.03.07
CPP 2015-01-15 수업내용 정리  (0) 2015.01.15
C 2015-01-09 실습  (0) 2015.01.09
Run-Time Check Failure #3 - The variable 'a' is being used without being initialized.  (0) 2014.05.14

아스키코드표

Programming/C,CPP,CS 2013. 5. 2. 22:04 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

DEC Char DEC Char DEC Char
0 Ctrl-@ NUL 43 + 86 V
1 Ctrl-A SOH 44 , 87 W
2 Ctrl-B STX 45 - 88 X
3 Ctrl-C ETX 46 . 89 Y
4 Ctrl-D EOT 47 / 90 Z
5 Ctrl-E ENQ 48 0 91 [
6 Ctrl-F ACK 49 1 92 \
7 Ctrl-G BEL 50 2 93 ]
8 Ctrl-H BS 51 3 94 ^
9 Ctrl-I HT 52 4 95 _
10 Ctrl-J LF 53 5 96 `
11 Ctrl-K VT 54 6 97 a
12 Ctrl-L FF 55 7 98 b
13 Ctrl-M CR 56 8 99 c
14 Ctrl-N SO 57 9 100 d
15 Ctrl-O SI 58 : 101 e
16 Ctrl-P DLE 59 ; 102 f
17 Ctrl-Q DCI 60 < 103 g
18 Ctrl-R DC2 61 = 104 h
19 Ctrl-S DC3 62 > 105 i
20 Ctrl-T DC4 63 ? 106 j
21 Ctrl-U NAK 64 @ 107 k
22 Ctrl-V SYN 65 A 108 l
23 Ctrl-W ETB 66 B 109 m
24 Ctrl-X CAN 67 C 110 n
25 Ctrl-Y EM 68 D 111 o
26 Ctrl-Z SUB 69 E 112 p
27 Ctrl-[ ESC 70 F 113 q
28 Ctrl-\ FS 71 G 114 r
29 Ctrl-] GS 72 H 115 s
30 Ctrl-^ RS 73 I 116 t
31 Ctrl_ US 74 J 117 u
32 Space 75 K 118 v
33 ! 76 L 119 w
34 " 77 M 120 x
35 # 78 N 121 y
36 $ 79 O 122 z
37 % 80 P 123 {
38 & 81 Q 124 |
39 ' 82 R 125 }
40 ( 83 S 126 ~
41 ) 84 T 127 DEL
42 * 85 U  

Android Battery Monitor

Programming/Android 2013. 4. 29. 18:43 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

Android Battery Monitor Code


batteryUsePerSec 를 수정하여 사용하세요



	public TextView batteryUsePerSec; // 배터리 Text View

	public void onCreate(Bundle savedInstanceState) {
		......
		batteryUsePerSec = (TextView) findViewById(R.id.batteryUsePerSec);
		......
        }

	public void onResume() {
		......
		IntentFilter filter = new IntentFilter();
		filter.addAction(Intent.ACTION_BATTERY_CHANGED);
		registerReceiver(mBRBattery, filter);
		......
	}

	BroadcastReceiver mBRBattery = new BroadcastReceiver()
	{

		@Override
		public void onReceive(Context context, Intent intent) {
			// TODO Auto-generated method stub
			String action = intent.getAction();
			if (action.equals(Intent.ACTION_BATTERY_CHANGED))
			{
				onBatteryChanged(intent);
			}
		}

		private void onBatteryChanged(Intent intent) {
			// TODO Auto-generated method stub
			int scale, level, ratio;
			scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, 100);
			level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 100);
			ratio = level * 100 / scale;
			
			batteryUsePerSec.setText(ratio + "");
			Log.d(ActivityTag, "onBatteryChanged()" + ratio);
		}
		
	};


'Programming > Android' 카테고리의 다른 글

파일 이름 일괄 변경 DarkNamer  (0) 2013.05.05
MyLocation Class  (0) 2013.05.04
Android google Map v2  (2) 2013.04.27
안드로이드 APK 추출하기  (0) 2013.04.25
Thread 와 Handler 테스트  (0) 2013.04.13